home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / bash / bash_108 / bash-108.zoo / bash-1.08 / y.tab.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-22  |  92.7 KB  |  3,385 lines

  1.  
  2. /*  A Bison parser, made from parse.y  */
  3.  
  4. #define    IF    258
  5. #define    THEN    259
  6. #define    ELSE    260
  7. #define    ELIF    261
  8. #define    FI    262
  9. #define    CASE    263
  10. #define    ESAC    264
  11. #define    FOR    265
  12. #define    WHILE    266
  13. #define    UNTIL    267
  14. #define    DO    268
  15. #define    DONE    269
  16. #define    FUNCTION    270
  17. #define    IN    271
  18. #define    BANG    272
  19. #define    WORD    273
  20. #define    NUMBER    274
  21. #define    AND_AND    275
  22. #define    OR_OR    276
  23. #define    GREATER_GREATER    277
  24. #define    LESS_LESS    278
  25. #define    LESS_AND    279
  26. #define    GREATER_AND    280
  27. #define    SEMI_SEMI    281
  28. #define    LESS_LESS_MINUS    282
  29. #define    AND_GREATER    283
  30. #define    LESS_GREATER    284
  31. #define    GREATER_BAR    285
  32. #define    yacc_EOF    286
  33.  
  34. #line 21 "parse.y"
  35.  
  36. #include <stdio.h>
  37. #include <signal.h>
  38. #include "shell.h"
  39. #include "flags.h"
  40.  
  41. #if defined (READLINE)
  42. #include <readline/readline.h>
  43. #endif /* READLINE */
  44.  
  45. #include <readline/history.h>
  46.  
  47. #define YYDEBUG 1
  48. extern int eof_encountered;
  49. extern int no_line_editing;
  50. extern int interactive, interactive_shell;
  51.  
  52. /* **************************************************************** */
  53. /*                                    */
  54. /*            "Forward" declarations                */
  55. /*                                    */
  56. /* **************************************************************** */
  57.  
  58.  
  59. /* This is kind of sickening.  In order to let these variables be seen by
  60.    all the functions that need them, I am forced to place their declarations
  61.    far away from the place where they should logically be found. */
  62.  
  63. /* prompt_string_pointer points to one of these, never to an actual string. */
  64. char *ps1_prompt, *ps2_prompt;
  65.  
  66. /* Handle on the current prompt string.  Indirectly points through
  67.    ps1_ or ps2_prompt. */
  68. char **prompt_string_pointer = (char **)NULL;
  69. char *current_prompt_string;
  70.  
  71. /* Variables to manage the task of reading here documents, because we need to
  72.    defer the reading until after a complete command has been collected. */
  73. REDIRECT *redirection_needing_here_doc = (REDIRECT *)NULL;
  74. int need_here_doc = 0;
  75.  
  76. #line 63 "parse.y"
  77. typedef union {
  78.   WORD_DESC *word;        /* the word that we read. */
  79.   int number;            /* the number that we read. */
  80.   WORD_LIST *word_list;
  81.   COMMAND *command;
  82.   REDIRECT *redirect;
  83.   ELEMENT element;
  84.   PATTERN_LIST *pattern;
  85. } YYSTYPE;
  86.  
  87. #ifndef YYLTYPE
  88. typedef
  89.   struct yyltype
  90.     {
  91.       int timestamp;
  92.       int first_line;
  93.       int first_column;
  94.       int last_line;
  95.       int last_column;
  96.       char *text;
  97.    }
  98.   yyltype;
  99.  
  100. #define YYLTYPE yyltype
  101. #endif
  102.  
  103. #include <stdio.h>
  104.  
  105. #ifndef __STDC__
  106. #define const
  107. #endif
  108.  
  109.  
  110.  
  111. #define    YYFINAL        212
  112. #define    YYFLAG        -32768
  113. #define    YYNTBASE    43
  114.  
  115. #define YYTRANSLATE(x) ((unsigned)(x) <= 286 ? yytranslate[x] : 66)
  116.  
  117. static const char yytranslate[] = {     0,
  118.      2,     2,     2,     2,     2,     2,     2,     2,     2,    33,
  119.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  120.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  121.      2,     2,     2,     2,     2,     2,     2,    31,     2,    41,
  122.     42,     2,     2,     2,    38,     2,     2,     2,     2,     2,
  123.      2,     2,     2,     2,     2,     2,     2,     2,    32,    37,
  124.      2,    36,     2,     2,     2,     2,     2,     2,     2,     2,
  125.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  126.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  127.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  128.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  129.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  130.      2,     2,    39,    35,    40,     2,     2,     2,     2,     2,
  131.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  132.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  133.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  134.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  135.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  136.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  137.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  138.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  139.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  140.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  141.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  142.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  143.      2,     2,     2,     2,     2,     1,     2,     3,     4,     5,
  144.      6,     7,     8,     9,    10,    11,    12,    13,    14,    15,
  145.     16,    17,    18,    19,    20,    21,    22,    23,    24,    25,
  146.     26,    27,    28,    29,    30,    34
  147. };
  148.  
  149. static const short yyrline[] = {     0,
  150.    102,   111,   118,   134,   144,   146,   150,   152,   154,   156,
  151.    158,   160,   162,   168,   174,   176,   178,   180,   182,   188,
  152.    194,   196,   198,   200,   202,   204,   206,   208,   218,   220,
  153.    224,   226,   230,   234,   245,   247,   251,   254,   257,   264,
  154.    266,   268,   270,   273,   275,   278,   280,   282,   287,   289,
  155.    291,   294,   296,   299,   302,   305,   308,   311,   315,   319,
  156.    321,   323,   328,   329,   333,   335,   339,   341,   345,   347,
  157.    351,   353,   362,   371,   372,   373,   375,   379,   381,   383,
  158.    385,   387,   389,   391,   398,   399,   400,   403,   404,   413,
  159.    420,   427,   436,   438,   440,   442,   444,   446,   453,   456
  160. };
  161.  
  162. static const char * const yytname[] = {     0,
  163. "error","$illegal.","IF","THEN","ELSE","ELIF","FI","CASE","ESAC","FOR",
  164. "WHILE","UNTIL","DO","DONE","FUNCTION","IN","BANG","WORD","NUMBER","AND_AND",
  165. "OR_OR","GREATER_GREATER","LESS_LESS","LESS_AND","GREATER_AND","SEMI_SEMI","LESS_LESS_MINUS","AND_GREATER","LESS_GREATER","GREATER_BAR",
  166. "'&'","';'","'\\n'","yacc_EOF","'|'","'>'","'<'","'-'","'{'","'}'",
  167. "'('","')'","inputunit"
  168. };
  169.  
  170. static const short yyr1[] = {     0,
  171.     43,    43,    43,    43,    44,    44,    45,    45,    45,    45,
  172.     45,    45,    45,    45,    45,    45,    45,    45,    45,    45,
  173.     45,    45,    45,    45,    45,    45,    45,    45,    45,    45,
  174.     46,    46,    47,    47,    48,    48,    49,    49,    49,    50,
  175.     50,    50,    50,    50,    50,    50,    50,    50,    50,    50,
  176.     50,    50,    50,    50,    50,    50,    50,    50,    51,    52,
  177.     52,    52,    53,    53,    54,    54,    55,    55,    56,    56,
  178.     57,    57,    58,    59,    59,    59,    59,    60,    60,    60,
  179.     60,    60,    60,    60,    61,    61,    61,    62,    62,    63,
  180.     63,    63,    64,    64,    64,    64,    64,    64,    65,    65
  181. };
  182.  
  183. static const short yyr2[] = {     0,
  184.      2,     1,     2,     1,     0,     2,     2,     2,     3,     3,
  185.      2,     3,     2,     3,     2,     3,     2,     3,     2,     3,
  186.      2,     3,     2,     3,     2,     2,     3,     2,     2,     3,
  187.      1,     1,     1,     2,     1,     2,     1,     1,     2,     6,
  188.      6,     7,     7,    10,    10,     6,     7,     6,     5,     7,
  189.      6,     5,     5,     3,     1,     5,     6,     4,     3,     4,
  190.      6,     5,     1,     2,     4,     4,     1,     2,     5,     5,
  191.      1,     3,     2,     1,     3,     3,     3,     4,     4,     4,
  192.      4,     4,     1,     2,     1,     1,     1,     0,     2,     1,
  193.      2,     2,     4,     4,     3,     3,     1,     2,     4,     1
  194. };
  195.  
  196. static const short yydefact[] = {     0,
  197.      0,    88,     0,     0,    88,    88,     0,     0,    31,     0,
  198.      0,     0,     0,     0,     0,     0,     0,     0,     2,     4,
  199.      0,     0,    88,    88,    32,    35,    37,   100,    38,    55,
  200.      0,    90,    97,     3,     0,     0,    88,    88,     0,     0,
  201.     88,    98,     0,     0,     0,     0,     0,     0,     0,     0,
  202.      0,     0,    11,    13,    15,    23,    26,    17,    21,    19,
  203.     25,    28,    29,     7,     8,     0,     0,    31,    36,    33,
  204.     39,     1,    88,    88,    91,    92,    88,    88,     0,    89,
  205.     73,    74,    83,     0,    88,     0,    88,    88,     0,     0,
  206.     88,    12,    14,    16,    24,    18,    22,    20,    27,    30,
  207.      9,    10,    59,    54,    34,     0,     0,    95,    96,     0,
  208.      0,    84,    88,    88,    88,    88,    88,    88,     0,    88,
  209.      5,    88,     0,     0,    88,    58,     0,    93,    94,     0,
  210.      0,    99,    88,    88,    49,     0,     0,     0,    76,    77,
  211.     75,     0,    63,    88,    67,     0,    88,    88,     0,     0,
  212.      0,    52,    53,     0,    56,     0,     0,    51,    78,    79,
  213.     80,    81,    82,    48,    64,    68,     0,    46,    71,     0,
  214.      0,     0,    40,     6,    86,    85,    87,    88,    41,    57,
  215.     50,    88,    88,    88,    88,    47,     0,    88,    42,    43,
  216.      0,    60,     0,     0,     0,    72,    65,    66,    88,    88,
  217.     88,    62,    69,    70,     0,     0,    61,    44,    45,     0,
  218.      0,     0
  219. };
  220.  
  221. static const short yydefgoto[] = {   210,
  222.    150,    25,    26,    71,    27,    28,    29,    30,   136,   142,
  223.    143,   144,   145,   170,    35,    81,    82,   178,    36,    31,
  224.    108,    83
  225. };
  226.  
  227. static const short yypact[] = {   151,
  228.     -8,-32768,     9,    18,-32768,-32768,    24,   350,     7,   390,
  229.     41,    46,    20,    33,    48,    54,    66,    80,-32768,-32768,
  230.     85,    92,-32768,-32768,-32768,-32768,   374,-32768,    77,-32768,
  231.     21,   104,    76,-32768,   108,   222,-32768,    86,   114,   121,
  232.     96,    76,    79,   120,   122,    36,    37,   123,   126,   127,
  233.    130,   131,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
  234. -32768,-32768,-32768,-32768,-32768,   111,    97,-32768,-32768,-32768,
  235.     77,-32768,-32768,-32768,   286,   286,-32768,-32768,   350,-32768,
  236. -32768,    99,    76,    -2,-32768,    -1,-32768,-32768,   116,   -11,
  237. -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
  238. -32768,-32768,-32768,-32768,-32768,   254,   254,    13,    13,   318,
  239.     63,    76,-32768,-32768,-32768,-32768,-32768,-32768,     4,-32768,
  240. -32768,-32768,   139,   150,-32768,-32768,   -11,-32768,-32768,   286,
  241.    286,-32768,-32768,-32768,-32768,   158,   222,   222,   222,   222,
  242.    222,   162,-32768,-32768,-32768,    11,-32768,-32768,   153,    47,
  243.    132,-32768,-32768,   -11,-32768,   175,   182,-32768,-32768,-32768,
  244.     56,    56,    56,-32768,-32768,-32768,    17,-32768,-32768,   -12,
  245.    177,   149,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
  246. -32768,-32768,-32768,-32768,-32768,-32768,   179,-32768,-32768,-32768,
  247.      8,    88,   222,   222,   222,-32768,   173,   190,-32768,-32768,
  248. -32768,-32768,-32768,-32768,   189,   164,-32768,-32768,-32768,   206,
  249.    210,-32768
  250. };
  251.  
  252. static const short yypgoto[] = {-32768,
  253. -32768,   -18,   184,-32768,-32768,-32768,-32768,   -87,    29,-32768,
  254.     78,-32768,    84,-32768,    -5,-32768,  -133,-32768,   -28,-32768,
  255.      2,    16
  256. };
  257.  
  258.  
  259. #define    YYLAST        427
  260.  
  261.  
  262. static const short yytable[] = {    39,
  263.     40,    32,   126,   159,   160,   161,   162,   163,    84,    86,
  264.     70,   120,    90,   118,   121,    33,   147,    66,    67,   168,
  265.    199,    80,   187,    42,    34,   186,    37,    23,   169,   188,
  266.     80,    80,    73,    74,   169,    38,    80,   122,    55,   155,
  267.     80,    41,   148,    80,   106,   107,   200,    43,   110,    80,
  268.     57,    58,   105,    72,    94,    96,   119,    56,    53,   161,
  269.    162,   163,   127,    54,   174,    60,   180,   133,   134,   135,
  270.     59,    61,   111,    95,    97,   113,   114,   109,   175,   176,
  271.    177,   123,   124,    62,   137,   138,   139,   140,   141,   146,
  272.     33,    33,   201,   134,   112,    10,   154,    63,    11,    12,
  273.     13,    14,    64,    15,    16,    17,    18,   128,   129,    65,
  274.     77,    78,    21,    22,   149,   167,   151,    85,   113,   114,
  275.     91,    33,    33,    73,    74,   132,    87,   156,   157,   115,
  276.    116,   117,   109,    88,    75,    76,    89,    92,   104,    93,
  277.     98,   171,   172,    99,   100,    33,    33,   101,   102,   191,
  278.    103,     1,   152,     2,   193,   194,   195,   125,     3,   198,
  279.      4,     5,     6,   153,   158,     7,   173,     8,     9,    10,
  280.    164,   179,    11,    12,    13,    14,   192,    15,    16,    17,
  281.     18,   181,   197,    19,    20,   182,    21,    22,   190,    23,
  282.    189,    24,     2,   205,   206,   207,   196,     3,   203,     4,
  283.      5,     6,   208,   209,     7,   211,    79,     9,    10,   212,
  284.     69,    11,    12,    13,    14,   204,    15,    16,    17,    18,
  285.    202,   165,    80,     0,     2,    21,    22,   166,    23,     3,
  286.     24,     4,     5,     6,     0,     0,     7,     0,    79,     9,
  287.     10,     0,     0,    11,    12,    13,    14,     0,    15,    16,
  288.     17,    18,     0,     0,    80,     0,     2,    21,    22,     0,
  289.     23,     3,    24,     4,     5,     6,     0,     0,     7,     0,
  290.      8,     9,    10,     0,     0,    11,    12,    13,    14,     0,
  291.     15,    16,    17,    18,     0,     0,    80,     0,     2,    21,
  292.     22,     0,    23,     3,    24,     4,     5,     6,     0,     0,
  293.      7,     0,     8,     9,    10,     0,     0,    11,    12,    13,
  294.     14,     0,    15,    16,    17,    18,     0,     0,     0,     0,
  295.      2,    21,    22,     0,    23,     3,    24,     4,     5,     6,
  296.      0,     0,     7,     0,     0,     9,    10,     0,     0,    11,
  297.     12,    13,    14,     0,    15,    16,    17,    18,     0,     0,
  298.     80,     0,     2,    21,    22,     0,    23,     3,    24,     4,
  299.      5,     6,     0,     0,     7,     0,     0,     9,    10,     0,
  300.      0,    11,    12,    13,    14,     0,    15,    16,    17,    18,
  301.      0,     0,     0,     0,     0,    21,    22,     0,    23,     0,
  302.     24,    68,    10,     0,     0,    11,    12,    13,    14,     0,
  303.     15,    16,    17,    18,     0,     0,     0,     0,     0,    21,
  304.     22,    44,    45,    46,    47,     0,    48,     0,    49,    50,
  305.      0,     0,     0,     0,     0,    51,    52
  306. };
  307.  
  308. static const short yycheck[] = {     5,
  309.      6,     0,    90,   137,   138,   139,   140,   141,    37,    38,
  310.     29,    13,    41,    16,    16,     0,    13,    23,    24,     9,
  311.     13,    33,    35,     8,    33,     9,    18,    39,    18,    42,
  312.     33,    33,    20,    21,    18,    18,    33,    39,    19,   127,
  313.     33,    18,    39,    33,    73,    74,    39,    41,    77,    33,
  314.     18,    19,    71,    33,    19,    19,    85,    38,    18,   193,
  315.    194,   195,    91,    18,    18,    18,   154,     5,     6,     7,
  316.     38,    18,    78,    38,    38,    20,    21,    76,    32,    33,
  317.     34,    87,    88,    18,   113,   114,   115,   116,   117,   118,
  318.     75,    76,     5,     6,    79,    19,   125,    18,    22,    23,
  319.     24,    25,    18,    27,    28,    29,    30,   106,   107,    18,
  320.     35,     4,    36,    37,   120,   144,   122,    32,    20,    21,
  321.     42,   106,   107,    20,    21,   110,    13,   133,   134,    31,
  322.     32,    33,   131,    13,    31,    32,    41,    18,    42,    18,
  323.     18,   147,   148,    18,    18,   130,   131,    18,    18,   178,
  324.     40,     1,    14,     3,   183,   184,   185,    42,     8,   188,
  325.     10,    11,    12,    14,     7,    15,    14,    17,    18,    19,
  326.      9,    40,    22,    23,    24,    25,   182,    27,    28,    29,
  327.     30,     7,   188,    33,    34,     4,    36,    37,    40,    39,
  328.     14,    41,     3,   199,   200,   201,    18,     8,    26,    10,
  329.     11,    12,    14,    40,    15,     0,    17,    18,    19,     0,
  330.     27,    22,    23,    24,    25,    26,    27,    28,    29,    30,
  331.    192,   144,    33,    -1,     3,    36,    37,   144,    39,     8,
  332.     41,    10,    11,    12,    -1,    -1,    15,    -1,    17,    18,
  333.     19,    -1,    -1,    22,    23,    24,    25,    -1,    27,    28,
  334.     29,    30,    -1,    -1,    33,    -1,     3,    36,    37,    -1,
  335.     39,     8,    41,    10,    11,    12,    -1,    -1,    15,    -1,
  336.     17,    18,    19,    -1,    -1,    22,    23,    24,    25,    -1,
  337.     27,    28,    29,    30,    -1,    -1,    33,    -1,     3,    36,
  338.     37,    -1,    39,     8,    41,    10,    11,    12,    -1,    -1,
  339.     15,    -1,    17,    18,    19,    -1,    -1,    22,    23,    24,
  340.     25,    -1,    27,    28,    29,    30,    -1,    -1,    -1,    -1,
  341.      3,    36,    37,    -1,    39,     8,    41,    10,    11,    12,
  342.     -1,    -1,    15,    -1,    -1,    18,    19,    -1,    -1,    22,
  343.     23,    24,    25,    -1,    27,    28,    29,    30,    -1,    -1,
  344.     33,    -1,     3,    36,    37,    -1,    39,     8,    41,    10,
  345.     11,    12,    -1,    -1,    15,    -1,    -1,    18,    19,    -1,
  346.     -1,    22,    23,    24,    25,    -1,    27,    28,    29,    30,
  347.     -1,    -1,    -1,    -1,    -1,    36,    37,    -1,    39,    -1,
  348.     41,    18,    19,    -1,    -1,    22,    23,    24,    25,    -1,
  349.     27,    28,    29,    30,    -1,    -1,    -1,    -1,    -1,    36,
  350.     37,    22,    23,    24,    25,    -1,    27,    -1,    29,    30,
  351.     -1,    -1,    -1,    -1,    -1,    36,    37
  352. };
  353. #define YYPURE 1
  354.  
  355. /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
  356. #line 3 "bison.simple"
  357.  
  358. /* Skeleton output parser for bison,
  359.    Copyright (C) 1984 Bob Corbett and Richard Stallman
  360.  
  361.    This program is free software; you can redistribute it and/or modify
  362.    it under the terms of the GNU General Public License as published by
  363.    the Free Software Foundation; either version 1, or (at your option)
  364.    any later version.
  365.  
  366.    This program is distributed in the hope that it will be useful,
  367.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  368.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  369.    GNU General Public License for more details.
  370.  
  371.    You should have received a copy of the GNU General Public License
  372.    along with this program; if not, write to the Free Software
  373.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  374.  
  375.  
  376. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__)
  377. #include <alloca.h>
  378. #endif
  379.  
  380. /* This is the parser code that is written into each bison parser
  381.   when the %semantic_parser declaration is not specified in the grammar.
  382.   It was written by Richard Stallman by simplifying the hairy parser
  383.   used when %semantic_parser is specified.  */
  384.  
  385. /* Note: there must be only one dollar sign in this file.
  386.    It is replaced by the list of actions, each action
  387.    as one case of the switch.  */
  388.  
  389. #define yyerrok        (yyerrstatus = 0)
  390. #define yyclearin    (yychar = YYEMPTY)
  391. #define YYEMPTY        -2
  392. #define YYEOF        0
  393. #define YYFAIL        goto yyerrlab;
  394. #define YYACCEPT    return(0)
  395. #define YYABORT     return(1)
  396. #define YYERROR        goto yyerrlab
  397.  
  398. #define YYTERROR    1
  399. #define YYERRCODE    256
  400.  
  401. #ifndef YYIMPURE
  402. #define YYLEX        yylex()
  403. #endif
  404.  
  405. #ifndef YYPURE
  406. #define YYLEX        yylex(&yylval, &yylloc)
  407. #endif
  408.  
  409. /* If nonreentrant, generate the variables here */
  410.  
  411. #ifndef YYIMPURE
  412.  
  413. int    yychar;            /*  the lookahead symbol        */
  414. YYSTYPE    yylval;            /*  the semantic value of the        */
  415.                 /*  lookahead symbol            */
  416.  
  417. YYLTYPE yylloc;            /*  location data for the lookahead    */
  418.                 /*  symbol                */
  419.  
  420. int yynerrs;            /*  number of parse errors so far       */
  421. #endif  /* YYIMPURE */
  422.  
  423. #if YYDEBUG != 0
  424. int yydebug;            /*  nonzero means print parse trace    */
  425. /* Since this is uninitialized, it does not stop multiple parsers
  426.    from coexisting.  */
  427. #endif
  428.  
  429. /*  YYMAXDEPTH indicates the initial size of the parser's stacks    */
  430.  
  431. #ifndef    YYMAXDEPTH
  432. #define YYMAXDEPTH 200
  433. #endif
  434.  
  435. /*  YYMAXLIMIT is the maximum size the stacks can grow to
  436.     (effective only if the built-in stack extension method is used).  */
  437.  
  438. #ifndef YYMAXLIMIT
  439. #define YYMAXLIMIT 10000
  440. #endif
  441.  
  442.  
  443. #line 90 "bison.simple"
  444. int
  445. yyparse()
  446. {
  447.   register int yystate;
  448.   register int yyn;
  449.   register short *yyssp;
  450.   register YYSTYPE *yyvsp;
  451.   YYLTYPE *yylsp;
  452.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  453.   int yychar1;        /*  lookahead token as an internal (translated) token number */
  454.  
  455.   short    yyssa[YYMAXDEPTH];    /*  the state stack            */
  456.   YYSTYPE yyvsa[YYMAXDEPTH];    /*  the semantic value stack        */
  457.   YYLTYPE yylsa[YYMAXDEPTH];    /*  the location stack            */
  458.  
  459.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  460.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  461.   YYLTYPE *yyls = yylsa;
  462.  
  463.   int yymaxdepth = YYMAXDEPTH;
  464.  
  465. #ifndef YYPURE
  466.   int yychar;
  467.   YYSTYPE yylval;
  468.   YYLTYPE yylloc;
  469.   int yynerrs;
  470. #endif
  471.  
  472.   YYSTYPE yyval;        /*  the variable used to return        */
  473.                 /*  semantic values from the action    */
  474.                 /*  routines                */
  475.  
  476.   int yylen;
  477.  
  478. #if YYDEBUG != 0
  479.   if (yydebug)
  480.     fprintf(stderr, "Starting parse\n");
  481. #endif
  482.  
  483.   yystate = 0;
  484.   yyerrstatus = 0;
  485.   yynerrs = 0;
  486.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  487.  
  488.   /* Initialize stack pointers.
  489.      Waste one element of value and location stack
  490.      so that they stay on the same level as the state stack.  */
  491.  
  492.   yyssp = yyss - 1;
  493.   yyvsp = yyvs;
  494.   yylsp = yyls;
  495.  
  496. /* Push a new state, which is found in  yystate  .  */
  497. /* In all cases, when you get here, the value and location stacks
  498.    have just been pushed. so pushing a state here evens the stacks.  */
  499. yynewstate:
  500.  
  501.   *++yyssp = yystate;
  502.  
  503.   if (yyssp >= yyss + yymaxdepth - 1)
  504.     {
  505.       /* Give user a chance to reallocate the stack */
  506.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  507.       YYSTYPE *yyvs1 = yyvs;
  508.       YYLTYPE *yyls1 = yyls;
  509.       short *yyss1 = yyss;
  510.  
  511.       /* Get the current used size of the three stacks, in elements.  */
  512.       int size = yyssp - yyss + 1;
  513.  
  514. #ifdef yyoverflow
  515.       /* Each stack pointer address is followed by the size of
  516.      the data in use in that stack, in bytes.  */
  517.       yyoverflow("parser stack overflow",
  518.          &yyss1, size * sizeof (*yyssp),
  519.          &yyvs1, size * sizeof (*yyvsp),
  520.          &yyls1, size * sizeof (*yylsp),
  521.          &yymaxdepth);
  522.  
  523.       yyss = yyss1; yyvs = yyvs1; yyls = yyls1;
  524. #else /* no yyoverflow */
  525.       /* Extend the stack our own way.  */
  526.       if (yymaxdepth >= YYMAXLIMIT)
  527.     yyerror("parser stack overflow");
  528.       yymaxdepth *= 2;
  529.       if (yymaxdepth > YYMAXLIMIT)
  530.     yymaxdepth = YYMAXLIMIT;
  531.       yyss = (short *) alloca (yymaxdepth * sizeof (*yyssp));
  532.       bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
  533.       yyvs = (YYSTYPE *) alloca (yymaxdepth * sizeof (*yyvsp));
  534.       bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
  535. #ifdef YYLSP_NEEDED
  536.       yyls = (YYLTYPE *) alloca (yymaxdepth * sizeof (*yylsp));
  537.       bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
  538. #endif
  539. #endif /* no yyoverflow */
  540.  
  541.       yyssp = yyss + size - 1;
  542.       yyvsp = yyvs + size - 1;
  543. #ifdef YYLSP_NEEDED
  544.       yylsp = yyls + size - 1;
  545. #endif
  546.  
  547. #if YYDEBUG != 0
  548.       if (yydebug)
  549.     fprintf(stderr, "Stack size increased to %d\n", yymaxdepth);
  550. #endif
  551.  
  552.       if (yyssp >= yyss + yymaxdepth - 1)
  553.     YYABORT;
  554.     }
  555.  
  556. #if YYDEBUG != 0
  557.   if (yydebug)
  558.     fprintf(stderr, "Entering state %d\n", yystate);
  559. #endif
  560.  
  561. /* Do appropriate processing given the current state.  */
  562. /* Read a lookahead token if we need one and don't already have one.  */
  563. yyresume:
  564.  
  565.   /* First try to decide what to do without reference to lookahead token.  */
  566.  
  567.   yyn = yypact[yystate];
  568.   if (yyn == YYFLAG)
  569.     goto yydefault;
  570.  
  571.   /* Not known => get a lookahead token if don't already have one.  */
  572.  
  573.   /* yychar is either YYEMPTY or YYEOF
  574.      or a valid token in external form.  */
  575.  
  576.   if (yychar == YYEMPTY)
  577.     {
  578. #if YYDEBUG != 0
  579.       if (yydebug)
  580.     fprintf(stderr, "Reading a token: ");
  581. #endif
  582.       yychar = YYLEX;
  583.     }
  584.  
  585.   /* Convert token to internal form (in yychar1) for indexing tables with */
  586.  
  587.   if (yychar <= 0)        /* This means end of input. */
  588.     {
  589.       yychar1 = 0;
  590.       yychar = YYEOF;        /* Don't call YYLEX any more */
  591.  
  592. #if YYDEBUG != 0
  593.       if (yydebug)
  594.     fprintf(stderr, "Now at end of input.\n");
  595. #endif
  596.     }
  597.   else
  598.     {
  599.       yychar1 = YYTRANSLATE(yychar);
  600.  
  601. #if YYDEBUG != 0
  602.       if (yydebug)
  603.     fprintf(stderr, "Next token is %d (%s)\n", yychar, yytname[yychar1]);
  604. #endif
  605.     }
  606.  
  607.   yyn += yychar1;
  608.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  609.     goto yydefault;
  610.  
  611.   yyn = yytable[yyn];
  612.  
  613.   /* yyn is what to do for this token type in this state.
  614.      Negative => reduce, -yyn is rule number.
  615.      Positive => shift, yyn is new state.
  616.        New state is final state => don't bother to shift,
  617.        just return success.
  618.      0, or most negative number => error.  */
  619.  
  620.   if (yyn < 0)
  621.     {
  622.       if (yyn == YYFLAG)
  623.     goto yyerrlab;
  624.       yyn = -yyn;
  625.       goto yyreduce;
  626.     }
  627.   else if (yyn == 0)
  628.     goto yyerrlab;
  629.  
  630.   if (yyn == YYFINAL)
  631.     YYACCEPT;
  632.  
  633.   /* Shift the lookahead token.  */
  634.  
  635. #if YYDEBUG != 0
  636.   if (yydebug)
  637.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  638. #endif
  639.  
  640.   /* Discard the token being shifted unless it is eof.  */
  641.   if (yychar != YYEOF)
  642.     yychar = YYEMPTY;
  643.  
  644.   *++yyvsp = yylval;
  645. #ifdef YYLSP_NEEDED
  646.   *++yylsp = yylloc;
  647. #endif
  648.  
  649.   /* count tokens shifted since error; after three, turn off error status.  */
  650.   if (yyerrstatus) yyerrstatus--;
  651.  
  652.   yystate = yyn;
  653.   goto yynewstate;
  654.  
  655. /* Do the default action for the current state.  */
  656. yydefault:
  657.  
  658.   yyn = yydefact[yystate];
  659.   if (yyn == 0)
  660.     goto yyerrlab;
  661.  
  662. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  663. yyreduce:
  664.   yylen = yyr2[yyn];
  665.   yyval = yyvsp[1-yylen]; /* implement default value of the action */
  666.  
  667. #if YYDEBUG != 0
  668.   if (yydebug)
  669.     {
  670.       if (yylen == 1)
  671.     fprintf (stderr, "Reducing 1 value via line %d, ",
  672.          yyrline[yyn]);
  673.       else
  674.     fprintf (stderr, "Reducing %d values via line %d, ",
  675.          yylen, yyrline[yyn]);
  676.     }
  677. #endif
  678.  
  679.  
  680.   switch (yyn) {
  681.  
  682. case 1:
  683. #line 103 "parse.y"
  684. {
  685.               /* Case of regular command.  Discard the error
  686.                  safety net,and return the command just parsed. */
  687.               global_command = yyvsp[-1].command;
  688.               eof_encountered = 0;
  689.               discard_parser_constructs (0);
  690.               YYACCEPT;
  691.             ;
  692.     break;}
  693. case 2:
  694. #line 112 "parse.y"
  695. {
  696.               /* Case of regular command, but not a very
  697.                  interesting one.  Return a NULL command. */
  698.               global_command = (COMMAND *)NULL;
  699.               YYACCEPT;
  700.             ;
  701.     break;}
  702. case 3:
  703. #line 120 "parse.y"
  704. {
  705.               /* Error during parsing.  Return NULL command. */
  706.               global_command = (COMMAND *)NULL;
  707.               eof_encountered = 0;
  708.               discard_parser_constructs (1);
  709.               if (interactive)
  710.                 {
  711.                   YYACCEPT;
  712.                 }
  713.               else
  714.                 {
  715.                   YYABORT;
  716.                 }
  717.             ;
  718.     break;}
  719. case 4:
  720. #line 135 "parse.y"
  721. {
  722.               /* Case of EOF seen by itself.  Do ignoreeof or 
  723.                  not. */
  724.               global_command = (COMMAND *)NULL;
  725.               handle_eof_input_unit ();
  726.               YYACCEPT;
  727.             ;
  728.     break;}
  729. case 5:
  730. #line 145 "parse.y"
  731. { yyval.word_list = (WORD_LIST *)NULL; ;
  732.     break;}
  733. case 6:
  734. #line 147 "parse.y"
  735. { yyval.word_list = make_word_list (yyvsp[0].word, yyvsp[-1].word_list); ;
  736.     break;}
  737. case 7:
  738. #line 151 "parse.y"
  739. { yyval.redirect = make_redirection ( 1, r_output_direction, yyvsp[0].word); ;
  740.     break;}
  741. case 8:
  742. #line 153 "parse.y"
  743. { yyval.redirect = make_redirection ( 0, r_input_direction, yyvsp[0].word); ;
  744.     break;}
  745. case 9:
  746. #line 155 "parse.y"
  747. { yyval.redirect = make_redirection (yyvsp[-2].number, r_output_direction, yyvsp[0].word); ;
  748.     break;}
  749. case 10:
  750. #line 157 "parse.y"
  751. { yyval.redirect = make_redirection (yyvsp[-2].number, r_input_direction, yyvsp[0].word); ;
  752.     break;}
  753. case 11:
  754. #line 159 "parse.y"
  755. { yyval.redirect = make_redirection ( 1, r_appending_to, yyvsp[0].word); ;
  756.     break;}
  757. case 12:
  758. #line 161 "parse.y"
  759. { yyval.redirect = make_redirection (yyvsp[-2].number, r_appending_to, yyvsp[0].word); ;
  760.     break;}
  761. case 13:
  762. #line 163 "parse.y"
  763. {
  764.               yyval.redirect = make_redirection ( 0, r_reading_until, yyvsp[0].word);
  765.               redirection_needing_here_doc = yyval.redirect;
  766.               need_here_doc = 1;
  767.             ;
  768.     break;}
  769. case 14:
  770. #line 169 "parse.y"
  771. {
  772.               yyval.redirect = make_redirection (yyvsp[-2].number, r_reading_until, yyvsp[0].word);
  773.               redirection_needing_here_doc = yyval.redirect;
  774.               need_here_doc = 1;
  775.             ;
  776.     break;}
  777. case 15:
  778. #line 175 "parse.y"
  779. { yyval.redirect = make_redirection ( 0, r_duplicating, yyvsp[0].number); ;
  780.     break;}
  781. case 16:
  782. #line 177 "parse.y"
  783. { yyval.redirect = make_redirection (yyvsp[-2].number, r_duplicating, yyvsp[0].number); ;
  784.     break;}
  785. case 17:
  786. #line 179 "parse.y"
  787. { yyval.redirect = make_redirection ( 1, r_duplicating, yyvsp[0].number); ;
  788.     break;}
  789. case 18:
  790. #line 181 "parse.y"
  791. { yyval.redirect = make_redirection (yyvsp[-2].number, r_duplicating, yyvsp[0].number); ;
  792.     break;}
  793. case 19:
  794. #line 183 "parse.y"
  795. {
  796.               yyval.redirect = make_redirection ( 0, r_deblank_reading_until, yyvsp[0].word);
  797.               redirection_needing_here_doc = yyval.redirect;
  798.               need_here_doc = 1;
  799.             ;
  800.     break;}
  801. case 20:
  802. #line 189 "parse.y"
  803. {
  804.               yyval.redirect = make_redirection (yyvsp[-2].number, r_deblank_reading_until, yyvsp[0].word);
  805.               redirection_needing_here_doc = yyval.redirect;
  806.               need_here_doc = 1;
  807.             ;
  808.     break;}
  809. case 21:
  810. #line 195 "parse.y"
  811. { yyval.redirect = make_redirection ( 1, r_close_this, 0); ;
  812.     break;}
  813. case 22:
  814. #line 197 "parse.y"
  815. { yyval.redirect = make_redirection (yyvsp[-2].number, r_close_this, 0); ;
  816.     break;}
  817. case 23:
  818. #line 199 "parse.y"
  819. { yyval.redirect = make_redirection ( 0, r_close_this, 0); ;
  820.     break;}
  821. case 24:
  822. #line 201 "parse.y"
  823. { yyval.redirect = make_redirection (yyvsp[-2].number, r_close_this, 0); ;
  824.     break;}
  825. case 25:
  826. #line 203 "parse.y"
  827. { yyval.redirect = make_redirection ( 1, r_err_and_out, yyvsp[0].word); ;
  828.     break;}
  829. case 26:
  830. #line 205 "parse.y"
  831. { yyval.redirect = make_redirection ( 1, r_err_and_out, yyvsp[0].word); ;
  832.     break;}
  833. case 27:
  834. #line 207 "parse.y"
  835. { yyval.redirect = make_redirection ( yyvsp[-2].number, r_input_output, yyvsp[0].word); ;
  836.     break;}
  837. case 28:
  838. #line 209 "parse.y"
  839. {
  840.               REDIRECT *t1, *t2;
  841.               extern WORD_DESC *copy_word ();
  842.  
  843.               t1 = make_redirection ( 0, r_input_direction, yyvsp[0].word);
  844.               t2 = make_redirection ( 1, r_output_direction, copy_word (yyvsp[0].word));
  845.               t1->next = t2;
  846.               yyval.redirect = t1;
  847.             ;
  848.     break;}
  849. case 29:
  850. #line 219 "parse.y"
  851. { yyval.redirect = make_redirection ( 1, r_output_force, yyvsp[0].word); ;
  852.     break;}
  853. case 30:
  854. #line 221 "parse.y"
  855. { yyval.redirect = make_redirection ( yyvsp[-2].number, r_output_force, yyvsp[0].word); ;
  856.     break;}
  857. case 31:
  858. #line 225 "parse.y"
  859. { yyval.element.word = yyvsp[0].word; yyval.element.redirect = 0; ;
  860.     break;}
  861. case 32:
  862. #line 227 "parse.y"
  863. { yyval.element.redirect = yyvsp[0].redirect; yyval.element.word = 0; ;
  864.     break;}
  865. case 33:
  866. #line 231 "parse.y"
  867. {
  868.               yyval.redirect = yyvsp[0].redirect;
  869.             ;
  870.     break;}
  871. case 34:
  872. #line 235 "parse.y"
  873.               register REDIRECT *t = yyvsp[-1].redirect;
  874.  
  875.               while (t->next)
  876.                 t = t->next;
  877.               t->next = yyvsp[0].redirect; 
  878.               yyval.redirect = yyvsp[-1].redirect;
  879.             ;
  880.     break;}
  881. case 35:
  882. #line 246 "parse.y"
  883. { yyval.command = make_simple_command (yyvsp[0].element, (COMMAND *)NULL); ;
  884.     break;}
  885. case 36:
  886. #line 248 "parse.y"
  887. { yyval.command = make_simple_command (yyvsp[0].element, yyvsp[-1].command); ;
  888.     break;}
  889. case 37:
  890. #line 252 "parse.y"
  891. { yyval.command = clean_simple_command (yyvsp[0].command); ;
  892.     break;}
  893. case 38:
  894. #line 255 "parse.y"
  895. { yyval.command = yyvsp[0].command; ;
  896.     break;}
  897. case 39:
  898. #line 258 "parse.y"
  899. {
  900.               yyval.command->redirects = yyvsp[0].redirect;
  901.               yyval.command = yyvsp[-1].command;
  902.             ;
  903.     break;}
  904. case 40:
  905. #line 265 "parse.y"
  906. { yyval.command = make_for_command (yyvsp[-4].word, (WORD_LIST *)add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command); ;
  907.     break;}
  908. case 41:
  909. #line 267 "parse.y"
  910. { yyval.command = make_for_command (yyvsp[-4].word, (WORD_LIST *)add_string_to_list ("$@", (WORD_LIST *)NULL), yyvsp[-1].command); ;
  911.     break;}
  912. case 42:
  913. #line 269 "parse.y"
  914. { yyval.command = make_for_command (yyvsp[-5].word, (WORD_LIST *)add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command); ;
  915.     break;}
  916. case 43:
  917. #line 271 "parse.y"
  918. { yyval.command = make_for_command (yyvsp[-5].word, (WORD_LIST *)add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command); ;
  919.     break;}
  920. case 44:
  921. #line 274 "parse.y"
  922. { yyval.command = make_for_command (yyvsp[-8].word, (WORD_LIST *)reverse_list (yyvsp[-5].word_list), yyvsp[-1].command); ;
  923.     break;}
  924. case 45:
  925. #line 276 "parse.y"
  926. { yyval.command = make_for_command (yyvsp[-8].word, (WORD_LIST *)reverse_list (yyvsp[-5].word_list), yyvsp[-1].command); ;
  927.     break;}
  928. case 46:
  929. #line 279 "parse.y"
  930. { yyval.command = make_case_command (yyvsp[-4].word, (PATTERN_LIST *)NULL); ;
  931.     break;}
  932. case 47:
  933. #line 281 "parse.y"
  934. { yyval.command = make_case_command (yyvsp[-5].word, yyvsp[-2].pattern); ;
  935.     break;}
  936. case 48:
  937. #line 283 "parse.y"
  938. { /* Nobody likes this...
  939.                  report_syntax_error ("Inserted `;;'"); */
  940.               yyval.command = make_case_command (yyvsp[-4].word, yyvsp[-1].pattern); ;
  941.     break;}
  942. case 49:
  943. #line 288 "parse.y"
  944. { yyval.command = make_if_command (yyvsp[-3].command, yyvsp[-1].command, (COMMAND *)NULL); ;
  945.     break;}
  946. case 50:
  947. #line 290 "parse.y"
  948. { yyval.command = make_if_command (yyvsp[-5].command, yyvsp[-3].command, yyvsp[-1].command); ;
  949.     break;}
  950. case 51:
  951. #line 292 "parse.y"
  952. { yyval.command = make_if_command (yyvsp[-4].command, yyvsp[-2].command, yyvsp[-1].command); ;
  953.     break;}
  954. case 52:
  955. #line 295 "parse.y"
  956. { yyval.command = make_while_command (yyvsp[-3].command, yyvsp[-1].command); ;
  957.     break;}
  958. case 53:
  959. #line 297 "parse.y"
  960. { yyval.command = make_until_command (yyvsp[-3].command, yyvsp[-1].command); ;
  961.     break;}
  962. case 54:
  963. #line 300 "parse.y"
  964. { yyvsp[-1].command->subshell = WANT_SUBSHELL; yyval.command = yyvsp[-1].command; ;
  965.     break;}
  966. case 55:
  967. #line 303 "parse.y"
  968. { yyval.command = yyvsp[0].command; ;
  969.     break;}
  970. case 56:
  971. #line 306 "parse.y"
  972. { yyval.command = make_function_def (yyvsp[-4].word, yyvsp[0].command); ;
  973.     break;}
  974. case 57:
  975. #line 309 "parse.y"
  976. { yyval.command = make_function_def (yyvsp[-4].word, yyvsp[0].command); ;
  977.     break;}
  978. case 58:
  979. #line 312 "parse.y"
  980. { yyval.command = make_function_def (yyvsp[-2].word, yyvsp[0].command); ;
  981.     break;}
  982. case 59:
  983. #line 316 "parse.y"
  984. { yyval.command = make_group_command (yyvsp[-1].command); ;
  985.     break;}
  986. case 60:
  987. #line 320 "parse.y"
  988. { yyval.command = make_if_command (yyvsp[-2].command, yyvsp[0].command, (COMMAND *)NULL); ;
  989.     break;}
  990. case 61:
  991. #line 322 "parse.y"
  992. { yyval.command = make_if_command (yyvsp[-4].command, yyvsp[-2].command, yyvsp[0].command); ;
  993.     break;}
  994. case 62:
  995. #line 324 "parse.y"
  996. { yyval.command = make_if_command (yyvsp[-3].command, yyvsp[-1].command, yyvsp[0].command); ;
  997.     break;}
  998. case 64:
  999. #line 330 "parse.y"
  1000. { yyvsp[0].pattern->next = yyvsp[-1].pattern; yyval.pattern = yyvsp[0].pattern; ;
  1001.     break;}
  1002. case 65:
  1003. #line 334 "parse.y"
  1004. { yyval.pattern = make_pattern_list (yyvsp[-2].word_list, yyvsp[0].command); ;
  1005.     break;}
  1006. case 66:
  1007. #line 336 "parse.y"
  1008. { yyval.pattern = make_pattern_list (yyvsp[-2].word_list, (COMMAND *)NULL); ;
  1009.     break;}
  1010. case 68:
  1011. #line 342 "parse.y"
  1012. { yyvsp[0].pattern->next = yyvsp[-1].pattern; yyval.pattern = yyvsp[0].pattern; ;
  1013.     break;}
  1014. case 69:
  1015. #line 346 "parse.y"
  1016. { yyval.pattern = make_pattern_list (yyvsp[-3].word_list, yyvsp[-1].command); ;
  1017.     break;}
  1018. case 70:
  1019. #line 348 "parse.y"
  1020. { yyval.pattern = make_pattern_list (yyvsp[-3].word_list, (COMMAND *)NULL); ;
  1021.     break;}
  1022. case 71:
  1023. #line 352 "parse.y"
  1024. { yyval.word_list = make_word_list (yyvsp[0].word, (WORD_LIST *)NULL); ;
  1025.     break;}
  1026. case 72:
  1027. #line 354 "parse.y"
  1028. { yyval.word_list = make_word_list (yyvsp[0].word, yyvsp[-2].word_list); ;
  1029.     break;}
  1030. case 73:
  1031. #line 363 "parse.y"
  1032. {
  1033.               yyval.command = yyvsp[0].command;
  1034.               if (need_here_doc)
  1035.                 make_here_document (redirection_needing_here_doc);
  1036.               need_here_doc = 0;
  1037.              ;
  1038.     break;}
  1039. case 76:
  1040. #line 374 "parse.y"
  1041. { yyval.command = command_connect (yyvsp[-2].command, 0, '&'); ;
  1042.     break;}
  1043. case 78:
  1044. #line 380 "parse.y"
  1045. { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, AND_AND); ;
  1046.     break;}
  1047. case 79:
  1048. #line 382 "parse.y"
  1049. { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, OR_OR); ;
  1050.     break;}
  1051. case 80:
  1052. #line 384 "parse.y"
  1053. { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, '&'); ;
  1054.     break;}
  1055. case 81:
  1056. #line 386 "parse.y"
  1057. { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, ';'); ;
  1058.     break;}
  1059. case 82:
  1060. #line 388 "parse.y"
  1061. { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, ';'); ;
  1062.     break;}
  1063. case 83:
  1064. #line 390 "parse.y"
  1065. { yyval.command = yyvsp[0].command; ;
  1066.     break;}
  1067. case 84:
  1068. #line 392 "parse.y"
  1069. {
  1070.               yyvsp[0].command->invert_pipeline = 1;
  1071.               yyval.command = yyvsp[0].command;
  1072.             ;
  1073.     break;}
  1074. case 90:
  1075. #line 414 "parse.y"
  1076. {
  1077.               yyval.command = yyvsp[0].command;
  1078.               if (need_here_doc)
  1079.                 make_here_document (redirection_needing_here_doc);
  1080.               need_here_doc = 0;
  1081.             ;
  1082.     break;}
  1083. case 91:
  1084. #line 421 "parse.y"
  1085. {
  1086.               yyval.command = command_connect (yyvsp[-1].command, (COMMAND *)NULL, '&');
  1087.               if (need_here_doc)
  1088.                 make_here_document (redirection_needing_here_doc);
  1089.               need_here_doc = 0;
  1090.             ;
  1091.     break;}
  1092. case 92:
  1093. #line 428 "parse.y"
  1094. {
  1095.               yyval.command = yyvsp[-1].command;
  1096.               if (need_here_doc)
  1097.                 make_here_document (redirection_needing_here_doc);
  1098.               need_here_doc = 0;
  1099.             ;
  1100.     break;}
  1101. case 93:
  1102. #line 437 "parse.y"
  1103. { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, AND_AND); ;
  1104.     break;}
  1105. case 94:
  1106. #line 439 "parse.y"
  1107. { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, OR_OR); ;
  1108.     break;}
  1109. case 95:
  1110. #line 441 "parse.y"
  1111. { yyval.command = command_connect (yyvsp[-2].command, yyvsp[0].command, '&'); ;
  1112.     break;}
  1113. case 96:
  1114. #line 443 "parse.y"
  1115. { yyval.command = command_connect (yyvsp[-2].command, yyvsp[0].command, ';'); ;
  1116.     break;}
  1117. case 97:
  1118. #line 445 "parse.y"
  1119. { yyval.command = yyvsp[0].command; ;
  1120.     break;}
  1121. case 98:
  1122. #line 447 "parse.y"
  1123. {
  1124.               yyvsp[0].command->invert_pipeline = 1;
  1125.               yyval.command = yyvsp[0].command;
  1126.             ;
  1127.     break;}
  1128. case 99:
  1129. #line 455 "parse.y"
  1130. { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, '|'); ;
  1131.     break;}
  1132. case 100:
  1133. #line 457 "parse.y"
  1134. { yyval.command = yyvsp[0].command; ;
  1135.     break;}
  1136. }
  1137.    /* the action file gets copied in in place of this dollarsign */
  1138. #line 327 "bison.simple"
  1139.  
  1140.   yyvsp -= yylen;
  1141.   yyssp -= yylen;
  1142. #ifdef YYLSP_NEEDED
  1143.   yylsp -= yylen;
  1144. #endif
  1145.  
  1146. #if YYDEBUG != 0
  1147.   if (yydebug)
  1148.     {
  1149.       short *ssp1 = yyss - 1;
  1150.       fprintf (stderr, "state stack now");
  1151.       while (ssp1 != yyssp)
  1152.     fprintf (stderr, " %d", *++ssp1);
  1153.       fprintf (stderr, "\n");
  1154.     }
  1155. #endif
  1156.  
  1157.   *++yyvsp = yyval;
  1158.  
  1159. #ifdef YYLSP_NEEDED
  1160.   yylsp++;
  1161.   if (yylen == 0)
  1162.     {
  1163.       yylsp->first_line = yylloc.first_line;
  1164.       yylsp->first_column = yylloc.first_column;
  1165.       yylsp->last_line = (yylsp-1)->last_line;
  1166.       yylsp->last_column = (yylsp-1)->last_column;
  1167.       yylsp->text = 0;
  1168.     }
  1169.   else
  1170.     {
  1171.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  1172.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  1173.     }
  1174. #endif
  1175.  
  1176.   /* Now "shift" the result of the reduction.
  1177.      Determine what state that goes to,
  1178.      based on the state we popped back to
  1179.      and the rule number reduced by.  */
  1180.  
  1181.   yyn = yyr1[yyn];
  1182.  
  1183.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  1184.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  1185.     yystate = yytable[yystate];
  1186.   else
  1187.     yystate = yydefgoto[yyn - YYNTBASE];
  1188.  
  1189.   goto yynewstate;
  1190.  
  1191. yyerrlab:   /* here on detecting error */
  1192.  
  1193.   if (! yyerrstatus)
  1194.     /* If not already recovering from an error, report this error.  */
  1195.     {
  1196.       ++yynerrs;
  1197.       yyerror("parse error");
  1198.     }
  1199.  
  1200.   if (yyerrstatus == 3)
  1201.     {
  1202.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  1203.  
  1204.       /* return failure if at end of input */
  1205.       if (yychar == YYEOF)
  1206.     YYABORT;
  1207.  
  1208. #if YYDEBUG != 0
  1209.       if (yydebug)
  1210.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  1211. #endif
  1212.  
  1213.       yychar = YYEMPTY;
  1214.     }
  1215.  
  1216.   /* Else will try to reuse lookahead token
  1217.      after shifting the error token.  */
  1218.  
  1219.   yyerrstatus = 3;        /* Each real token shifted decrements this */
  1220.  
  1221.   goto yyerrhandle;
  1222.  
  1223. yyerrdefault:  /* current state does not do anything special for the error token. */
  1224.  
  1225. #if 0
  1226.   /* This is wrong; only states that explicitly want error tokens
  1227.      should shift them.  */
  1228.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  1229.   if (yyn) goto yydefault;
  1230. #endif
  1231.  
  1232. yyerrpop:   /* pop the current state because it cannot handle the error token */
  1233.  
  1234.   if (yyssp == yyss) YYABORT;
  1235.   yyvsp--;
  1236.   yystate = *--yyssp;
  1237. #ifdef YYLSP_NEEDED
  1238.   yylsp--;
  1239. #endif
  1240.  
  1241. #if YYDEBUG != 0
  1242.   if (yydebug)
  1243.     {
  1244.       short *ssp1 = yyss - 1;
  1245.       fprintf (stderr, "Error: state stack now");
  1246.       while (ssp1 != yyssp)
  1247.     fprintf (stderr, " %d", *++ssp1);
  1248.       fprintf (stderr, "\n");
  1249.     }
  1250. #endif
  1251.  
  1252. yyerrhandle:
  1253.  
  1254.   yyn = yypact[yystate];
  1255.   if (yyn == YYFLAG)
  1256.     goto yyerrdefault;
  1257.  
  1258.   yyn += YYTERROR;
  1259.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  1260.     goto yyerrdefault;
  1261.  
  1262.   yyn = yytable[yyn];
  1263.   if (yyn < 0)
  1264.     {
  1265.       if (yyn == YYFLAG)
  1266.     goto yyerrpop;
  1267.       yyn = -yyn;
  1268.       goto yyreduce;
  1269.     }
  1270.   else if (yyn == 0)
  1271.     goto yyerrpop;
  1272.  
  1273.   if (yyn == YYFINAL)
  1274.     YYACCEPT;
  1275.  
  1276. #if YYDEBUG != 0
  1277.   if (yydebug)
  1278.     fprintf(stderr, "Shifting error token, ");
  1279. #endif
  1280.  
  1281.   *++yyvsp = yylval;
  1282. #ifdef YYLSP_NEEDED
  1283.   *++yylsp = yylloc;
  1284. #endif
  1285.  
  1286.   yystate = yyn;
  1287.   goto yynewstate;
  1288. }
  1289. #line 459 "parse.y"
  1290.  
  1291.  
  1292. /* Initial size to allocate for tokens, and the
  1293.    amount to grow them by. */
  1294. #define TOKEN_DEFAULT_GROW_SIZE 512
  1295.  
  1296. /* The token currently being read. */
  1297. int current_token = 0;
  1298.  
  1299. /* The last read token, or NULL.  read_token () uses this for context
  1300.    checking. */
  1301. int last_read_token = 0;
  1302.  
  1303. /* The token read prior to last_read_token. */
  1304. int token_before_that = 0;
  1305.  
  1306. /* Global var is non-zero when end of file has been reached. */
  1307. int EOF_Reached = 0;
  1308.  
  1309. /* yy_getc () returns the next available character from input or EOF.
  1310.    yy_ungetc (c) makes `c' the next character to read.
  1311.    init_yy_io (get, unget), makes the function `get' the installed function
  1312.    for getting the next character, and makes `unget' the installed function
  1313.    for un-getting a character. */
  1314. return_EOF ()            /* does nothing good. */
  1315. {
  1316.   return (EOF);
  1317. }
  1318.  
  1319. /* Variables containing the current get and unget functions. */
  1320.  
  1321. /* Some stream `types'. */
  1322. #define st_stream 0
  1323. #define st_string 1
  1324.  
  1325. Function *get_yy_char = return_EOF;
  1326. Function *unget_yy_char = return_EOF;
  1327. int yy_input_type = st_stream;
  1328. FILE *yy_input_dev = (FILE *)NULL;
  1329.  
  1330. /* The current stream name.  In the case of a file, this is a filename. */
  1331. char *stream_name = (char *)NULL;
  1332.  
  1333. /* Function to set get_yy_char and unget_yy_char. */
  1334. init_yy_io (get_function, unget_function, type, location)
  1335.      Function *get_function, *unget_function;
  1336.      int type;
  1337.      FILE *location;
  1338. {
  1339.   get_yy_char = get_function;
  1340.   unget_yy_char = unget_function;
  1341.   yy_input_type = type;
  1342.   yy_input_dev = location;
  1343. }
  1344.  
  1345. /* Call this to get the next character of input. */
  1346. yy_getc ()
  1347. {
  1348.   return (*get_yy_char) ();
  1349. }
  1350.  
  1351. /* Call this to unget C.  That is, to make C the next character
  1352.    to be read. */
  1353. yy_ungetc (c)
  1354. {
  1355.   return (*unget_yy_char) (c);
  1356. }
  1357.  
  1358. /* **************************************************************** */
  1359. /*                                    */
  1360. /*          Let input be read from readline ().            */
  1361. /*                                    */
  1362. /* **************************************************************** */
  1363.  
  1364. #if defined (READLINE)
  1365. char *current_readline_prompt = (char *)NULL;
  1366. char *current_readline_line = (char *)NULL;
  1367. int current_readline_line_index = 0;
  1368.  
  1369. static int readline_initialized_yet = 0;
  1370. int
  1371. yy_readline_get ()
  1372. {
  1373.   if (!current_readline_line)
  1374.     {
  1375.       char *readline ();
  1376.       SigHandler *old_sigint;
  1377.       extern sighandler sigint_sighandler ();
  1378.       extern int interrupt_immediately;
  1379.  
  1380. #if defined (JOB_CONTROL)
  1381.       extern int shell_pgrp, job_control;
  1382. #endif
  1383.  
  1384.       if (!readline_initialized_yet)
  1385.     {
  1386.       initialize_readline ();
  1387.       readline_initialized_yet = 1;
  1388.     }
  1389.  
  1390. #if defined (JOB_CONTROL)
  1391.       if (job_control)
  1392.     give_terminal_to (shell_pgrp);
  1393. #endif /* JOB_CONTROL */
  1394.  
  1395.       old_sigint = (SigHandler *)signal (SIGINT, sigint_sighandler);
  1396.       interrupt_immediately++;
  1397.  
  1398.       if (!current_readline_prompt)
  1399.     current_readline_line = readline ("");
  1400.       else
  1401.     current_readline_line = readline (current_readline_prompt);
  1402.  
  1403.       interrupt_immediately--;
  1404.       signal (SIGINT, old_sigint);
  1405.  
  1406.       /* Reset the prompt to whatever is in the decoded value of
  1407.      prompt_string_pointer. */
  1408.       reset_readline_prompt ();
  1409.  
  1410.       current_readline_line_index = 0;
  1411.  
  1412.       if (!current_readline_line)
  1413.     {
  1414.       current_readline_line_index = 0;
  1415.       return (EOF);
  1416.     }
  1417.  
  1418.       current_readline_line =
  1419.     (char *)xrealloc (current_readline_line,
  1420.               2 + strlen (current_readline_line));
  1421.       strcat (current_readline_line, "\n");
  1422.     }
  1423.  
  1424.   if (!current_readline_line[current_readline_line_index])
  1425.     {
  1426.       free (current_readline_line);
  1427.       current_readline_line = (char *)NULL;
  1428.       return (yy_readline_get ());
  1429.     }
  1430.   else
  1431.     {
  1432.       int c = current_readline_line[current_readline_line_index++];
  1433.       return (c);
  1434.     }
  1435. }
  1436.  
  1437. int
  1438. yy_readline_unget (c)
  1439. {
  1440.   if (current_readline_line_index && current_readline_line)
  1441.     current_readline_line[--current_readline_line_index] = c;
  1442.   return (c);
  1443. }
  1444.   
  1445. with_input_from_stdin ()
  1446. {
  1447.   init_yy_io (yy_readline_get, yy_readline_unget,
  1448.           st_string, (FILE *)current_readline_line);
  1449.   stream_name = savestring ("readline stdin");
  1450. }
  1451.  
  1452. #else  /* !READLINE */
  1453.  
  1454. with_input_from_stdin ()
  1455. {
  1456.   with_input_from_stream (stdin, "stdin");
  1457. }
  1458. #endif    /* !READLINE */
  1459.  
  1460. /* **************************************************************** */
  1461. /*                                    */
  1462. /*   Let input come from STRING.  STRING is zero terminated.        */
  1463. /*                                    */
  1464. /* **************************************************************** */
  1465.  
  1466. int
  1467. yy_string_get ()
  1468. {
  1469.   /* If the string doesn't exist, or is empty, EOF found. */
  1470.   if (!(char *)yy_input_dev || !*(char *)yy_input_dev)
  1471.     return (EOF);
  1472.   else
  1473.     {
  1474.       register char *temp = (char *)yy_input_dev;
  1475.       int c = *temp++;
  1476.       yy_input_dev = (FILE *)temp;
  1477.       return (c);
  1478.     }
  1479. }
  1480.  
  1481. int
  1482. yy_string_unget (c)
  1483.      int c;
  1484. {
  1485.   register char *temp = (char *)yy_input_dev;
  1486.   *(--temp) = c;
  1487.   yy_input_dev = (FILE *)temp;
  1488.   return (c);
  1489. }
  1490.  
  1491. with_input_from_string (string, name)
  1492.      char *string;
  1493.      char *name;
  1494. {
  1495.   init_yy_io (yy_string_get, yy_string_unget, st_string, (FILE *)string);
  1496.   stream_name = savestring (name);
  1497. }
  1498.  
  1499. /* **************************************************************** */
  1500. /*                                    */
  1501. /*             Let input come from STREAM.            */
  1502. /*                                    */
  1503. /* **************************************************************** */
  1504.  
  1505. int
  1506. yy_stream_get ()
  1507. {
  1508.   if (yy_input_dev)
  1509. #if defined (USG)
  1510.     return (sysv_getc (yy_input_dev));
  1511. #else
  1512.     return (getc (yy_input_dev));
  1513. #endif    /* USG */
  1514.   else return (EOF);
  1515. }
  1516.  
  1517. int
  1518. yy_stream_unget (c)
  1519.      int c;
  1520. {
  1521.   return (ungetc (c, yy_input_dev));
  1522. }
  1523.  
  1524. with_input_from_stream (stream, name)
  1525.      FILE *stream;
  1526.      char *name;
  1527. {
  1528.   init_yy_io (yy_stream_get, yy_stream_unget, st_stream, stream);
  1529.   stream_name = savestring (name);
  1530. }
  1531.  
  1532. typedef struct stream_saver {
  1533.   struct stream_saver *next;
  1534.   Function *getter, *putter;
  1535.   int type, line;
  1536.   char *location, *name;
  1537. } STREAM_SAVER;
  1538.  
  1539. /* The globally known line number. */
  1540. int line_number = 0;
  1541.  
  1542. STREAM_SAVER *stream_list = (STREAM_SAVER *)NULL;
  1543.  
  1544. push_stream ()
  1545. {
  1546.   STREAM_SAVER *temp = (STREAM_SAVER *)xmalloc (sizeof (STREAM_SAVER));
  1547.   temp->type = yy_input_type;
  1548.   temp->location = (char *)yy_input_dev;
  1549.   temp->getter = get_yy_char;
  1550.   temp->putter = unget_yy_char;
  1551.   temp->line = line_number;
  1552.   temp->name = stream_name; stream_name = (char *)NULL;
  1553.   temp->next = stream_list;
  1554.   stream_list = temp;
  1555.   EOF_Reached = line_number = 0;
  1556. }
  1557.  
  1558. pop_stream ()
  1559. {
  1560.   if (!stream_list)
  1561.     {
  1562.       EOF_Reached = 1;
  1563.     }
  1564.   else
  1565.     {
  1566.       STREAM_SAVER *temp = stream_list;
  1567.     
  1568.       EOF_Reached = 0;
  1569.       stream_list = stream_list->next;
  1570.  
  1571.       if (stream_name)
  1572.     free (stream_name);
  1573.       stream_name = temp->name;
  1574.  
  1575.       init_yy_io (temp->getter, temp->putter, temp->type, (FILE *)temp->location);
  1576.       line_number = temp->line;
  1577.       free (temp);
  1578.     }
  1579. }
  1580.  
  1581. /*
  1582.  * This is used to inhibit alias expansion and reserved word recognition
  1583.  * inside case statement pattern lists.  A `case statement pattern list'
  1584.  * is:
  1585.  *    everything between the `in' in a `case word in' and the next ')'
  1586.  *    or `esac'
  1587.  *    everything between a `;;' and the next `)' or `esac'
  1588.  */
  1589. static int in_case_pattern_list = 0;
  1590.  
  1591. #if defined (ALIAS)
  1592. /*
  1593.  * Pseudo-global variables used in implementing token-wise alias expansion.
  1594.  */
  1595.  
  1596. static int expand_next_token = 0;
  1597. static char *current_token_being_expanded = (char *)NULL;
  1598. static char *pending_token_being_expanded = (char *)NULL;
  1599.  
  1600. /*
  1601.  * Pushing and popping strings.  This works together with shell_getc to 
  1602.  * implement alias expansion on a per-token basis.
  1603.  */
  1604.  
  1605. typedef struct string_saver {
  1606.   struct string_saver *next;
  1607.   int expand_alias;  /* value to set expand_alias to when string is popped */
  1608.   char *saved_line;
  1609.   int saved_line_size, saved_line_index, saved_line_terminator;
  1610.   char *saved_token_being_expanded;
  1611. } STRING_SAVER;
  1612.  
  1613. STRING_SAVER *pushed_string_list = (STRING_SAVER *)NULL;
  1614.  
  1615. static void save_expansion ();
  1616.  
  1617. /*
  1618.  * Push the current shell_input_line onto a stack of such lines and make S
  1619.  * the current input.  Used when expanding aliases.  EXPAND is used to set
  1620.  * the value of expand_next_token when the string is popped, so that the
  1621.  * word after the alias in the original line is handled correctly when the
  1622.  * alias expands to multiple words.  TOKEN is the token that was expanded
  1623.  * into S; it is saved and used to prevent infinite recursive expansion.
  1624.  */
  1625. static void
  1626. push_string (s, expand, token)
  1627.      char *s;
  1628.      int expand;
  1629.      char *token;
  1630. {
  1631.   extern char *shell_input_line;
  1632.   extern int shell_input_line_size, shell_input_line_index,
  1633.          shell_input_line_terminator;
  1634.   STRING_SAVER *temp = (STRING_SAVER *) xmalloc (sizeof (STRING_SAVER));
  1635.  
  1636.   temp->expand_alias = expand;
  1637.   temp->saved_line = shell_input_line;
  1638.   temp->saved_line_size = shell_input_line_size;
  1639.   temp->saved_line_index = shell_input_line_index;
  1640.   temp->saved_line_terminator = shell_input_line_terminator;
  1641.   temp->saved_token_being_expanded = current_token_being_expanded;
  1642.   temp->next = pushed_string_list;
  1643.   pushed_string_list = temp;
  1644.  
  1645.   save_expansion (token);
  1646.  
  1647.   current_token_being_expanded = token;
  1648.   shell_input_line = s;
  1649.   shell_input_line_size = strlen (s);
  1650.   shell_input_line_index = 0;
  1651.   shell_input_line_terminator = '\0';
  1652.   expand_next_token = 0;
  1653. }
  1654.  
  1655. /*
  1656.  * Make the top of the pushed_string stack be the current shell input.
  1657.  * Only called when there is something on the stack.  Called from shell_getc
  1658.  * when it thinks it has consumed the string generated by an alias expansion
  1659.  * and needs to return to the original input line.
  1660.  */
  1661. static void
  1662. pop_string ()
  1663. {
  1664.   extern char *shell_input_line;
  1665.   extern int shell_input_line_size, shell_input_line_index,
  1666.          shell_input_line_terminator;
  1667.   STRING_SAVER *t;
  1668.  
  1669.   if (shell_input_line)
  1670.     free (shell_input_line);
  1671.   shell_input_line = pushed_string_list->saved_line;
  1672.   shell_input_line_index = pushed_string_list->saved_line_index;
  1673.   shell_input_line_size = pushed_string_list->saved_line_size;
  1674.   shell_input_line_terminator = pushed_string_list->saved_line_terminator;
  1675.   expand_next_token = pushed_string_list->expand_alias;
  1676.   pending_token_being_expanded = pushed_string_list->saved_token_being_expanded;
  1677.   t = pushed_string_list;
  1678.   pushed_string_list = pushed_string_list->next;
  1679.   free((char *)t);
  1680. }
  1681.  
  1682. static void
  1683. free_string_list ()
  1684. {
  1685.   register STRING_SAVER *t = pushed_string_list, *t1;
  1686.  
  1687.   while (t)
  1688.     {
  1689.       t1 = t->next;
  1690.       if (t->saved_line)
  1691.     free (t->saved_line);
  1692.       if (t->saved_token_being_expanded)
  1693.     free (t->saved_token_being_expanded);
  1694.       free ((char *)t);
  1695.       t = t1;
  1696.     }
  1697.   pushed_string_list = (STRING_SAVER *)NULL;
  1698. }
  1699.  
  1700. /* This is a stack to save the values of all tokens for which alias
  1701.    expansion has been performed during the current call to read_token ().
  1702.    It is used to prevent alias expansion loops:
  1703.  
  1704.       alias foo=bar
  1705.       alias bar=baz
  1706.       alias baz=foo
  1707.  
  1708.    Ideally this would be taken care of by push and pop string, but because
  1709.    of when strings are popped the stack will not contain the correct
  1710.    strings to test against.  (The popping is done in shell_getc, so that when
  1711.    the current string is exhausted, shell_getc can simply pop that string off
  1712.    the stack, restore the previous string, and continue with the character
  1713.    following the token whose expansion was originally pushed on the stack.)
  1714.  
  1715.    What we really want is a record of all tokens that have been expanded for
  1716.    aliases during the `current' call to read_token().  This does that, at the
  1717.    cost of being somewhat special-purpose (OK, OK vile and unclean).  Brian,
  1718.    you had better rewrite this whole piece of garbage before the next version
  1719.    is released.
  1720. */
  1721.  
  1722. typedef struct _exp_saver {
  1723.       struct _exp_saver *next;
  1724.       char *saved_token;
  1725. } EXPANSION_SAVER;
  1726.  
  1727. EXPANSION_SAVER *expanded_token_stack = (EXPANSION_SAVER *)NULL;
  1728.  
  1729. static void
  1730. save_expansion (s)
  1731.      char *s;
  1732. {
  1733.   EXPANSION_SAVER *t;
  1734.  
  1735.   t = (EXPANSION_SAVER *) xmalloc (sizeof (EXPANSION_SAVER));
  1736.   t->saved_token = savestring (s);
  1737.   t->next = expanded_token_stack;
  1738.   expanded_token_stack = t;
  1739. }
  1740.  
  1741. /*
  1742.  * Return 1 if TOKEN has already been expanded in the current `stack' of
  1743.  * expansions.  If it has been expanded already, it will appear as the value
  1744.  * of saved_token for some entry in the stack of expansions created for the
  1745.  * current token being expanded.
  1746.  */
  1747. static int
  1748. token_has_been_expanded (token)
  1749.      char *token;
  1750. {
  1751.   register EXPANSION_SAVER *t = expanded_token_stack;
  1752.  
  1753.   while (t)
  1754.     {
  1755.       if (STREQ (token, t->saved_token))
  1756.     return (1);
  1757.       t = t->next;
  1758.     }
  1759.   return (0);
  1760. }
  1761.  
  1762. static void
  1763. free_expansion_stack ()
  1764. {
  1765.   register EXPANSION_SAVER *t = expanded_token_stack, *t1;
  1766.  
  1767.   while (t)
  1768.     {
  1769.       t1 = t->next;
  1770.       free (t->saved_token);
  1771.       free (t);
  1772.       t = t1;
  1773.     }
  1774.   expanded_token_stack = (EXPANSION_SAVER *)NULL;
  1775. }
  1776.  
  1777. #endif /* ALIAS */
  1778.  
  1779. /* Return a line of text, taken from wherever yylex () reads input.
  1780.    If there is no more input, then we return NULL. */
  1781. char *
  1782. read_a_line ()
  1783. {
  1784.   char *line_buffer = (char *)NULL;
  1785.   int indx = 0, buffer_size = 0;
  1786.   int c;
  1787.  
  1788.   while (1)
  1789.     {
  1790.       c = yy_getc ();
  1791.  
  1792.       if (c == 0)
  1793.     continue;
  1794.  
  1795.       /* If there is no more input, then we return NULL. */
  1796.       if (c == EOF)
  1797.     {
  1798.       c = '\n';
  1799.       if (!line_buffer)
  1800.         return ((char *)NULL);
  1801.     }
  1802.  
  1803.       /* `+2' in case the final (200'th) character in the buffer is a newline;
  1804.      otherwise the code below that NULL-terminates it will write over the
  1805.      201st slot and kill the range checking in free(). */
  1806.       if (indx + 2 > buffer_size)
  1807.     if (!buffer_size)
  1808.       line_buffer = (char *)xmalloc (buffer_size = 200);
  1809.     else
  1810.       line_buffer = (char *)xrealloc (line_buffer, buffer_size += 200);
  1811.  
  1812.       line_buffer[indx++] = c;
  1813.       if (c == '\n')
  1814.     {
  1815.       line_buffer[indx] = '\0';
  1816.       return (line_buffer);
  1817.     }
  1818.     }
  1819. }
  1820.  
  1821. /* Return a line as in read_a_line (), but insure that the prompt is
  1822.    the secondary prompt. */
  1823. char *
  1824. read_secondary_line ()
  1825. {
  1826.   prompt_string_pointer = &ps2_prompt;
  1827.   prompt_again ();
  1828.   return (read_a_line ());
  1829. }
  1830.  
  1831.  
  1832. /* **************************************************************** */
  1833. /*                                    */
  1834. /*                YYLEX ()                */
  1835. /*                                    */
  1836. /* **************************************************************** */
  1837.  
  1838. /* Reserved words.  These are only recognized as the first word of a
  1839.    command.  TOKEN_WORD_ALIST. */
  1840. struct {
  1841.   char *word;
  1842.   int token;
  1843. } token_word_alist[] = {
  1844.   {"if", IF},
  1845.   {"then", THEN},
  1846.   {"else", ELSE},
  1847.   {"elif", ELIF},
  1848.   {"fi", FI},
  1849.   {"case", CASE},
  1850.   {"esac", ESAC},
  1851.   {"for", FOR},
  1852.   {"while", WHILE},
  1853.   {"until", UNTIL},
  1854.   {"do", DO},
  1855.   {"done", DONE},
  1856.   {"in", IN},
  1857.   {"function", FUNCTION},
  1858.   {"{", '{'},
  1859.   {"}", '}'},
  1860.   {"!", BANG},
  1861.   {(char *)NULL, 0}
  1862. };
  1863.  
  1864. /* Where shell input comes from.  History expansion is performed on each
  1865.    line, when the shell is interactive. */
  1866. char *shell_input_line = (char *)NULL;
  1867. int shell_input_line_index = 0;
  1868. int shell_input_line_size = 0;    /* amount allocated for shell_input_line */
  1869. int shell_input_line_len = 0;    /* strlen (shell_input_line) */
  1870.  
  1871. /* Either zero, or EOF. */
  1872. int shell_input_line_terminator = 0;
  1873.  
  1874. /* Return the next shell input character.  This always reads characters
  1875.    from shell_input_line; when that line is exhausted, it is time to
  1876.    read the next line. */
  1877. int
  1878. shell_getc (remove_quoted_newline)
  1879.      int remove_quoted_newline;
  1880. {
  1881.   extern int login_shell;
  1882.   int c;
  1883.  
  1884.   QUIT;    /* XXX this is experimental */
  1885.  
  1886. #if defined (ALIAS)
  1887.   /* If shell_input_line[shell_input_line_index] == 0, but there is
  1888.      something on the pushed list of strings, then we don't want to go
  1889.      off and get another line.  We let the code down below handle it. */
  1890.  
  1891.   if (!shell_input_line || ((!shell_input_line[shell_input_line_index]) &&
  1892.                 (pushed_string_list == (STRING_SAVER *)NULL)))
  1893. #else /* !ALIAS */
  1894.   if (!shell_input_line || !shell_input_line[shell_input_line_index])
  1895. #endif /* !ALIAS */
  1896.     {
  1897.       register int i, l;
  1898.       char *pre_process_line (), *expansions;
  1899.  
  1900.       restart_read_next_line:
  1901.  
  1902.       line_number++;
  1903.  
  1904.     restart_read:
  1905.  
  1906.       QUIT;    /* XXX experimental */
  1907.  
  1908.       i = 0;
  1909.       shell_input_line_terminator = 0;
  1910.  
  1911. #if defined (JOB_CONTROL)
  1912.       notify_and_cleanup ();
  1913. #endif
  1914.  
  1915.       clearerr (stdin);
  1916.       while (c = yy_getc ())
  1917.     {
  1918.       if (i + 2 > shell_input_line_size)
  1919.         shell_input_line = (char *)
  1920.           xrealloc (shell_input_line, shell_input_line_size += 256);
  1921.  
  1922.       if (c == EOF)
  1923.         {
  1924.           clearerr (stdin);
  1925.  
  1926.           if (!i)
  1927.         shell_input_line_terminator = EOF;
  1928.  
  1929.           shell_input_line[i] = '\0';
  1930.           break;
  1931.         }
  1932.  
  1933.       shell_input_line[i++] = c;
  1934.  
  1935.       if (c == '\n')
  1936.         {
  1937.           shell_input_line[--i] = '\0';
  1938.           break;
  1939.         }
  1940.     }
  1941.       shell_input_line_index = 0;
  1942.       shell_input_line_len = i;        /* == strlen (shell_input_line) */
  1943.  
  1944.       if (!shell_input_line[0])
  1945.     goto after_pre_process;
  1946.  
  1947.       if (interactive)
  1948.     {
  1949.       expansions = pre_process_line (shell_input_line, 1, 1);
  1950.  
  1951.       free (shell_input_line);
  1952.       shell_input_line = expansions;
  1953.       shell_input_line_len = shell_input_line ?
  1954.                  strlen (shell_input_line) :
  1955.                  0;
  1956.       /* We have to force the xrealloc below because we don't know the
  1957.          true allocated size of shell_input_line anymore. */
  1958.       shell_input_line_size = shell_input_line_len;
  1959.     }
  1960.  
  1961.   after_pre_process:
  1962.       if (shell_input_line)
  1963.     {
  1964.       if (echo_input_at_read)
  1965.         fprintf (stderr, "%s\n", shell_input_line);
  1966.     }
  1967.       else
  1968.     {
  1969.       shell_input_line_size = 0;
  1970.       prompt_string_pointer = ¤t_prompt_string;
  1971.       prompt_again ();
  1972.       goto restart_read;
  1973.     }
  1974.  
  1975.       /* Add the newline to the end of this string, iff the string does
  1976.      not already end in an EOF character.  */
  1977.       if (shell_input_line_terminator != EOF)
  1978.     {
  1979.       l = shell_input_line_len;    /* was a call to strlen */
  1980.  
  1981.       if (l + 3 > shell_input_line_size)
  1982.         shell_input_line = (char *)xrealloc (shell_input_line,
  1983.                     1 + (shell_input_line_size += 2));
  1984.  
  1985.       strcpy (shell_input_line + l, "\n");
  1986.     }
  1987.     }
  1988.   
  1989.   c = shell_input_line[shell_input_line_index];
  1990.  
  1991.   if (c)
  1992.     shell_input_line_index++;
  1993.  
  1994.   if (c == '\\' && remove_quoted_newline &&
  1995.       shell_input_line[shell_input_line_index] == '\n')
  1996.     {
  1997.     prompt_again ();
  1998.     goto restart_read_next_line;
  1999.     }
  2000.  
  2001. #if defined (ALIAS)
  2002.   /*
  2003.    * If c is NULL, we have reached the end of the current input string.  If
  2004.    * pushed_string_list is non-empty, it's time to pop to the previous string
  2005.    * because we have fully consumed the result of the last alias expansion.
  2006.    * Do it transparently; just return the next character of the string popped
  2007.    * to.  We need to hang onto current_token_being_expanded until the token
  2008.    * currently being read has been recognized; we can't restore it in
  2009.    * pop_string () because the token currently being read would be
  2010.    * inappropriately compared with it.  We defer restoration until the next
  2011.    * call to read_token ().
  2012.    */
  2013.  
  2014.   if (!c && (pushed_string_list != (STRING_SAVER *)NULL))
  2015.     {
  2016.       pop_string ();
  2017.       c = shell_input_line[shell_input_line_index];
  2018.       if (c)
  2019.     shell_input_line_index++;
  2020.     }
  2021. #endif /* ALIAS */
  2022.  
  2023.   if (!c && shell_input_line_terminator == EOF)
  2024.     {
  2025.       if (shell_input_line_index != 0)
  2026.     return ('\n');
  2027.       else
  2028.     return (EOF);
  2029.     }
  2030.  
  2031.   return (c);
  2032. }
  2033.  
  2034. /* Put C back into the input for the shell. */
  2035. shell_ungetc (c)
  2036.      int c;
  2037. {
  2038.   if (shell_input_line && shell_input_line_index)
  2039.     shell_input_line[--shell_input_line_index] = c;
  2040. }
  2041.  
  2042. /* Discard input until CHARACTER is seen. */
  2043. discard_until (character)
  2044.      int character;
  2045. {
  2046.   int c;
  2047.   while ((c = shell_getc (0)) != EOF && c != character)
  2048.     ;
  2049.   if (c != EOF )
  2050.     shell_ungetc (c);
  2051. }
  2052.  
  2053. #if defined (HISTORY_REDITING)
  2054. /* Tell readline () that we have some text for it to edit. */
  2055. re_edit (text)
  2056.      char *text;
  2057. {
  2058. #if defined (READLINE)
  2059.   if (strcmp (stream_name, "readline stdin") == 0)
  2060.     bash_re_edit (text);
  2061. #endif /* READLINE */
  2062. }
  2063. #endif /* HISTORY_REDITING */
  2064.  
  2065. /* Non-zero means do no history expansion on this line, regardless
  2066.    of what history_expansion says. */
  2067. int history_expansion_inhibited = 0;
  2068.  
  2069. /* Do pre-processing on LINE.  If PRINT_CHANGES is non-zero, then
  2070.    print the results of expanding the line if there were any changes.
  2071.    If there is an error, return NULL, otherwise the expanded line is
  2072.    returned.  If ADDIT is non-zero the line is added to the history
  2073.    list after history expansion.  ADDIT is just a suggestion;
  2074.    REMEMBER_ON_HISTORY can veto, and does.
  2075.    Right now this does history expansion. */
  2076. char *
  2077. pre_process_line (line, print_changes, addit)
  2078.      char *line;
  2079.      int print_changes, addit;
  2080. {
  2081.   char *return_value = line;
  2082.   int expanded = 0;
  2083.  
  2084.   extern int history_expansion;
  2085.   extern int remember_on_history;
  2086.   int history_expand ();
  2087.   char *history_value;
  2088.  
  2089.   /* History expand the line.  If this results in no errors, then
  2090.      add that line to the history if ADDIT is non-zero. */
  2091.   if (!history_expansion_inhibited && history_expansion)
  2092.     {
  2093.       expanded = history_expand (line, &history_value);
  2094.  
  2095.       if (expanded)
  2096.     {
  2097.       if (print_changes)
  2098.         fprintf (stderr, "%s\n", history_value);
  2099.  
  2100.       /* If there was an error, return NULL. */
  2101.       if (expanded < 0)
  2102.         {
  2103.           free (history_value);
  2104.  
  2105. #if defined (HISTORY_REDITING)
  2106.           /* New hack.  We can allow the user to edit the
  2107.          failed history expansion. */
  2108.           re_edit (line);
  2109. #endif /* HISTORY_REDITING */
  2110.           return ((char *)NULL);
  2111.         }
  2112.     }
  2113.  
  2114.       /* Let other expansions know that return_value can be free'ed,
  2115.      and that a line has been added to the history list.  Note
  2116.      that we only add lines that have something in them. */
  2117.       expanded = 1;
  2118.       return_value = history_value;
  2119.     }
  2120.  
  2121.   if (addit && remember_on_history && *return_value)
  2122.     {
  2123.       extern int history_control;
  2124.       extern int history_lines_this_session;
  2125.  
  2126.       switch (history_control)
  2127.     {
  2128.       case 0:
  2129.         add_history (return_value);
  2130.         history_lines_this_session++;
  2131.         break;
  2132.       case 1:
  2133.         if (*return_value != ' ')
  2134.           {
  2135.         add_history (return_value);
  2136.         history_lines_this_session++;
  2137.           }
  2138.         break;
  2139.       case 2:
  2140.         {
  2141.           HIST_ENTRY *temp;
  2142.  
  2143.           using_history ();
  2144.           temp = previous_history ();
  2145.           if (!temp || (strcmp (temp->line, return_value) != 0))
  2146.         {
  2147.           add_history (return_value);
  2148.           history_lines_this_session++;
  2149.         }
  2150.           using_history ();
  2151.         }
  2152.         break;
  2153.     }
  2154.     }
  2155.  
  2156.   if (!expanded)
  2157.     return_value = savestring (line);
  2158.  
  2159.   return (return_value);
  2160. }
  2161.  
  2162.  
  2163. /* Place to remember the token.  We try to keep the buffer
  2164.    at a reasonable size, but it can grow. */
  2165. char *token = (char *)NULL;
  2166.  
  2167. /* Current size of the token buffer. */
  2168. int token_buffer_size = 0;
  2169.  
  2170. /* Command to read_token () explaining what we want it to do. */
  2171. #define READ 0
  2172. #define RESET 1
  2173. #define prompt_is_ps1 \
  2174.       (!prompt_string_pointer || prompt_string_pointer == &ps1_prompt)
  2175.  
  2176. /* Function for yyparse to call.  yylex keeps track of
  2177.    the last two tokens read, and calls read_token.  */
  2178.  
  2179. yylex ()
  2180. {
  2181.   if (interactive && (!current_token || current_token == '\n'))
  2182.     {
  2183.       /* Before we print a prompt, we might have to check mailboxes.
  2184.      We do this only if it is time to do so. Notice that only here
  2185.      is the mail alarm reset; nothing takes place in check_mail ()
  2186.      except the checking of mail.  Please don't change this. */
  2187.       if (prompt_is_ps1 && time_to_check_mail ())
  2188.     {
  2189.       check_mail ();
  2190.       reset_mail_timer ();
  2191.     }
  2192.  
  2193.       /* Allow the execution of a random command just before the printing
  2194.      of each primary prompt.  If the shell variable PROMPT_COMMAND
  2195.      is set then the value of it is the command to execute. */
  2196.       if (prompt_is_ps1)
  2197.     {
  2198.       char *command_to_execute = get_string_value ("PROMPT_COMMAND");
  2199.  
  2200.       if (command_to_execute)
  2201.         {
  2202.           extern Function *last_shell_builtin, *this_shell_builtin;
  2203.           extern int last_command_exit_value;
  2204.           Function *temp_last, *temp_this;
  2205.           int temp_exit_value, temp_eof_encountered;
  2206.  
  2207.           temp_last = last_shell_builtin;
  2208.           temp_this = this_shell_builtin;
  2209.           temp_exit_value = last_command_exit_value;
  2210.           temp_eof_encountered = eof_encountered;
  2211.  
  2212.           parse_and_execute
  2213.         (savestring (command_to_execute), "PROMPT_COMMAND");
  2214.  
  2215.           last_shell_builtin = temp_last;
  2216.           this_shell_builtin = temp_this;
  2217.           last_command_exit_value = temp_exit_value;
  2218.           eof_encountered = temp_eof_encountered;
  2219.         }
  2220.     }
  2221.       prompt_again ();
  2222.     }
  2223.  
  2224.   token_before_that = last_read_token;
  2225.   last_read_token = current_token;
  2226.   current_token = read_token (READ);
  2227.   return (current_token);
  2228. }
  2229.  
  2230. /* Called from shell.c when Control-C is typed at top level.  Or
  2231.    by the error rule at top level. */
  2232. reset_parser ()
  2233. {
  2234.   read_token (RESET);
  2235. }
  2236.   
  2237. /* When non-zero, we have read the required tokens
  2238.    which allow ESAC to be the next one read. */
  2239. static int allow_esac_as_next = 0;
  2240.  
  2241. /* When non-zero, accept single '{' as a token itself. */
  2242. static int allow_open_brace = 0;
  2243.  
  2244. /* DELIMITER is the value of the delimiter that is currently
  2245.    enclosing, or zero for none. */
  2246. static int delimiter = 0;
  2247. static int old_delimiter = 0;
  2248.  
  2249. /* When non-zero, an open-brace used to create a group is awaiting a close
  2250.    brace partner. */
  2251. static int open_brace_awaiting_satisfaction = 0;
  2252.  
  2253. /* If non-zero, it is the token that we want read_token to return regardless
  2254.    of what text is (or isn't) present to be read.  read_token resets this. */
  2255. int token_to_read = 0;
  2256.  
  2257. /* Read the next token.  Command can be READ (normal operation) or 
  2258.    RESET (to normalize state). */
  2259. read_token (command)
  2260.      int command;
  2261. {
  2262.   extern int interactive_shell;    /* Whether the current shell is interactive. */
  2263.   int character;        /* Current character. */
  2264.   int peek_char;        /* Temporary look-ahead character. */
  2265.   int result;            /* The thing to return. */
  2266.   WORD_DESC *the_word;        /* The value for YYLVAL when a WORD is read. */
  2267.  
  2268.   if (token_buffer_size < TOKEN_DEFAULT_GROW_SIZE)
  2269.     {
  2270.       if (token)
  2271.     free (token);
  2272.       token = (char *)xmalloc (token_buffer_size = TOKEN_DEFAULT_GROW_SIZE);
  2273.     }
  2274.  
  2275.   if (command == RESET)
  2276.     {
  2277.       delimiter = old_delimiter = 0;
  2278.       open_brace_awaiting_satisfaction = 0;
  2279.       in_case_pattern_list = 0;
  2280.  
  2281. #if defined (ALIAS)
  2282.       if (pushed_string_list)
  2283.     {
  2284.       free_string_list ();
  2285.       pushed_string_list = (STRING_SAVER *)NULL;
  2286.     }
  2287.       if (pending_token_being_expanded)
  2288.     {
  2289.       free (pending_token_being_expanded);
  2290.       pending_token_being_expanded = (char *)NULL;
  2291.     }
  2292.       if (current_token_being_expanded)
  2293.     {
  2294.       free (current_token_being_expanded);
  2295.       current_token_being_expanded = (char *)NULL;
  2296.     }
  2297.  
  2298.       if (expanded_token_stack)
  2299.     {
  2300.       free_expansion_stack ();
  2301.       expanded_token_stack = (EXPANSION_SAVER *)NULL;
  2302.     }
  2303. #endif /* ALIAS */
  2304.  
  2305.       if (shell_input_line)
  2306.     {
  2307.       free (shell_input_line);
  2308.       shell_input_line = (char *)NULL;
  2309.       shell_input_line_size = shell_input_line_index = 0;
  2310.     }
  2311.       last_read_token = '\n';
  2312.       token_to_read = '\n';
  2313.       return;
  2314.     }
  2315.  
  2316.   if (token_to_read)
  2317.     {
  2318.       int rt = token_to_read;
  2319.       token_to_read = 0;
  2320.       return (rt);
  2321.     }
  2322.  
  2323. #if defined (ALIAS)
  2324.   /*
  2325.    * Now we can replace current_token_being_expanded with 
  2326.    * pending_token_being_expanded, since the token that would be 
  2327.    * inappropriately compared has already been returned.
  2328.    *
  2329.    * To see why restoring current_token_being_expanded in pop_string ()
  2330.    * could be a problem, consider "alias foo=foo".  Then try to
  2331.    * expand `foo'.  The initial value of current_token_being_expanded is
  2332.    * NULL, so that is what is pushed onto pushed_string_list as the
  2333.    * value of saved_token_being_expanded.  "foo" then becomes shell_input_line.
  2334.    * read_token calls shell_getc for `f', `o', `o', and then shell_getc
  2335.    * hits the end of shell_input_line.  pushed_string_list is not empty
  2336.    * so it gets popped.  If we were to blindly restore
  2337.    * current_token_being_expanded at this point, `foo' would be compared
  2338.    * with a NULL string in the check for recursive expansion, and would
  2339.    * infinitely recurse.
  2340.    */
  2341.   if (pending_token_being_expanded)
  2342.     {
  2343.       if (current_token_being_expanded)
  2344.     free (current_token_being_expanded);
  2345.       current_token_being_expanded = pending_token_being_expanded;
  2346.       pending_token_being_expanded = (char *)NULL;
  2347.     }
  2348.  
  2349.   /* If we hit read_token () and there are no saved strings on the
  2350.      pushed_string_list, then we are no longer currently expanding a
  2351.      token.  This can't be done in pop_stream, because pop_stream
  2352.      may pop the stream before the current token has finished being
  2353.      completely expanded (consider what happens when we alias foo to foo,
  2354.      and then try to expand it). */
  2355.   if (!pushed_string_list && current_token_being_expanded)
  2356.     {
  2357.       free (current_token_being_expanded);
  2358.       current_token_being_expanded = (char *)NULL;
  2359.  
  2360.       if (expanded_token_stack)
  2361.     {
  2362.       free_expansion_stack ();
  2363.       expanded_token_stack = (EXPANSION_SAVER *)NULL;
  2364.     }
  2365.     }
  2366.  
  2367.   /* This is a place to jump back to once we have successfully expanded a
  2368.      token with an alias and pushed the string with push_string () */
  2369. re_read_token:
  2370.  
  2371. #endif /* ALIAS */
  2372.  
  2373.   /* Read a single word from input.  Start by skipping blanks. */
  2374.   while ((character = shell_getc (1)) != EOF && whitespace (character));
  2375.  
  2376.   if (character == EOF)
  2377.     return (yacc_EOF);
  2378.  
  2379.   if (character == '#' && !interactive)
  2380.     {
  2381.       /* A comment.  Discard until EOL or EOF, and then return a newline. */
  2382.       discard_until ('\n');
  2383.       shell_getc (0);
  2384.  
  2385.       /* If we're about to return an unquoted newline, we can go and collect
  2386.      the text of any pending here document. */
  2387.       if (need_here_doc)
  2388.     make_here_document (redirection_needing_here_doc);
  2389.       need_here_doc = 0;
  2390.  
  2391.       return ('\n');
  2392.     }
  2393.  
  2394.   if (character == '\n')
  2395.     {
  2396.       /* If we're about to return an unquoted newline, we can go and collect
  2397.      the text of any pending here document. */
  2398.       if (need_here_doc)
  2399.     make_here_document (redirection_needing_here_doc);
  2400.       need_here_doc = 0;
  2401.  
  2402.       return (character);
  2403.     }
  2404.  
  2405.   if (member (character, "()<>;&|"))
  2406.     {
  2407.       /* Please note that the shell does not allow whitespace to
  2408.      appear in between tokens which are character pairs, such as
  2409.      "<<" or ">>".  I believe this is the correct behaviour. */
  2410.  
  2411.       if (character == (peek_char = shell_getc (1)))
  2412.     {
  2413.       switch (character)
  2414.         {
  2415.           /* If '<' then we could be at "<<" or at "<<-".  We have to
  2416.          look ahead one more character. */
  2417.         case '<':
  2418.           peek_char = shell_getc (1);
  2419.           if (peek_char == '-')
  2420.         return (LESS_LESS_MINUS);
  2421.           else
  2422.         {
  2423.           shell_ungetc (peek_char);
  2424.           return (LESS_LESS);
  2425.         }
  2426.  
  2427.         case '>': return (GREATER_GREATER);
  2428.         case ';':
  2429.               in_case_pattern_list = 1;
  2430.               return (SEMI_SEMI);
  2431.         case '&': return (AND_AND);
  2432.         case '|': return (OR_OR);
  2433.         }
  2434.     }
  2435.       else
  2436.     {
  2437.       if (peek_char == '&')
  2438.         {
  2439.           switch (character)
  2440.         {
  2441.         case '<': return (LESS_AND);
  2442.         case '>': return (GREATER_AND);
  2443.         }
  2444.         }
  2445.       if (character == '<' && peek_char == '>')
  2446.         return (LESS_GREATER);
  2447.       if (character == '>' && peek_char == '|')
  2448.         return (GREATER_BAR);
  2449.       if (peek_char == '>' && character == '&')
  2450.         return (AND_GREATER);
  2451.     }
  2452.       shell_ungetc (peek_char);
  2453.  
  2454.       /* If we look like we are reading the start of a function
  2455.      definition, then let the reader know about it so that
  2456.      we will do the right thing with `{'. */
  2457.       if (character == ')' &&
  2458.       last_read_token == '(' && token_before_that == WORD)
  2459.     allow_open_brace = 1;
  2460.  
  2461.       if (in_case_pattern_list && (character == ')'))
  2462.     in_case_pattern_list = 0;
  2463.  
  2464.       return (character);
  2465.     }
  2466.  
  2467.   /* Hack <&- (close stdin) case. */
  2468.   if (character == '-')
  2469.     {
  2470.       switch (last_read_token)
  2471.     {
  2472.     case LESS_AND:
  2473.     case GREATER_AND:
  2474.       return (character);
  2475.     }
  2476.     }
  2477.   
  2478.   /* Okay, if we got this far, we have to read a word.  Read one,
  2479.      and then check it against the known ones. */
  2480.   {
  2481.     /* Index into the token that we are building. */
  2482.     int token_index = 0;
  2483.  
  2484.     /* ALL_DIGITS becomes zero when we see a non-digit. */
  2485.     int all_digits = digit (character);
  2486.  
  2487.     /* DOLLAR_PRESENT becomes non-zero if we see a `$'. */
  2488.     int dollar_present = 0;
  2489.  
  2490.     /* QUOTED becomes non-zero if we see one of ("), ('), (`), or (\). */
  2491.     int quoted = 0;
  2492.  
  2493.     /* Non-zero means to ignore the value of the next character, and just
  2494.        to add it no matter what. */
  2495.     int pass_next_character = 0;
  2496.  
  2497.     /* Non-zero means parsing a dollar-paren construct.  It is the count of
  2498.        un-quoted closes we need to see. */
  2499.     int dollar_paren_level = 0;
  2500.  
  2501.     /* Non-zero means parsing a dollar-bracket construct ($[...]).  It is
  2502.        the count of un-quoted `]' characters we need to see. */
  2503.     int dollar_bracket_level = 0;
  2504.  
  2505.     /* Another level variable.  This one is for dollar_parens inside of
  2506.        double-quotes. */
  2507.     int delimited_paren_level = 0;
  2508.  
  2509.     for (;;)
  2510.       {
  2511.     if (character == EOF)
  2512.       goto got_token;
  2513.  
  2514.     if (pass_next_character)
  2515.       {
  2516.         pass_next_character = 0;
  2517.         goto got_character;
  2518.       }
  2519.  
  2520.       if (delimiter && character == '\\' && delimiter != '\'')
  2521.     {
  2522.       peek_char = shell_getc (0);
  2523.       if (peek_char != '\\')
  2524.         shell_ungetc (peek_char);
  2525.       else
  2526.         {
  2527.           token[token_index++] = character;
  2528.           goto got_character;
  2529.         }
  2530.     }
  2531.  
  2532.     /* Handle backslashes.  Quote lots of things when not inside of
  2533.        double-quotes, quote some things inside of double-quotes. */
  2534.        
  2535.     if (character == '\\' && delimiter != '\'')
  2536.       {
  2537.         peek_char = shell_getc (0);
  2538.  
  2539.         /* Backslash-newline is ignored in all cases excepting
  2540.            when quoted with single quotes. */
  2541.         if (peek_char == '\n')
  2542.           {
  2543.         character = '\n';
  2544.         goto next_character;
  2545.           }
  2546.         else
  2547.           {
  2548.         shell_ungetc (peek_char);
  2549.  
  2550.         /* If the next character is to be quoted, do it now. */
  2551.         if (!delimiter || delimiter == '`' ||
  2552.             ((delimiter == '"' ) &&
  2553.              (member (peek_char, slashify_in_quotes))))
  2554.           {
  2555.             pass_next_character++;
  2556.             quoted = 1;
  2557.             goto got_character;
  2558.           }
  2559.           }
  2560.       }
  2561.  
  2562.     /* This is a hack, in its present form.  If a backquote substitution
  2563.        appears within double quotes, everything within the backquotes
  2564.        should be read as part of a single word.  Jesus.  Now I see why
  2565.        Korn introduced the $() form. */
  2566.     if (delimiter && delimiter == '"' && character == '`')
  2567.       {
  2568.         old_delimiter = delimiter;
  2569.         delimiter = character;
  2570.         goto got_character;
  2571.       }
  2572.  
  2573.     if (delimiter)
  2574.       {
  2575.         if (character == delimiter)
  2576.           {
  2577.         if (delimited_paren_level)
  2578.           {
  2579. #if defined (NOTDEF)
  2580.             report_error ("Expected ')' before %c", character);
  2581.             return ('\n');
  2582. #else
  2583.             goto got_character;
  2584. #endif /* NOTDEF */
  2585.           }
  2586.  
  2587.         delimiter = 0;
  2588.  
  2589.         if (old_delimiter == '"' && character == '`')
  2590.           {
  2591.             delimiter = old_delimiter;
  2592.             old_delimiter = 0;
  2593.           }
  2594.  
  2595.         goto got_character;
  2596.           }
  2597.       }
  2598.  
  2599.     if (!delimiter || delimiter == '`' || delimiter == '"')
  2600.       {
  2601.         if (character == '$')
  2602.           {
  2603.         peek_char = shell_getc (1);
  2604.         shell_ungetc (peek_char);
  2605.         if (peek_char == '(')
  2606.           {
  2607.             if (!delimiter)
  2608.               dollar_paren_level++;
  2609.             else
  2610.               delimited_paren_level++;
  2611.  
  2612.             pass_next_character++;
  2613.             goto got_character;
  2614.           }
  2615.         else if (peek_char == '[')
  2616.           {
  2617.             if (!delimiter)
  2618.               dollar_bracket_level++;
  2619.  
  2620.             pass_next_character++;
  2621.             goto got_character;
  2622.           }
  2623.           }
  2624.  
  2625.         /* If we are parsing a $() or $[] construct, we need to balance
  2626.            parens and brackets inside the construct.  This whole function
  2627.            could use a rewrite. */
  2628.         if (character == '(')
  2629.           {
  2630.         if (delimiter && delimited_paren_level)
  2631.           delimited_paren_level++;
  2632.  
  2633.         if (!delimiter && dollar_paren_level)
  2634.           dollar_paren_level++;
  2635.           }
  2636.  
  2637.         if (character == '[')
  2638.           {
  2639.         if (!delimiter && dollar_bracket_level)
  2640.           dollar_bracket_level++;
  2641.           }
  2642.  
  2643.         /* This code needs to take into account whether we are inside a
  2644.            case statement pattern list, and whether this paren is supposed
  2645.            to terminate it (hey, it could happen).  It's not as simple
  2646.            as just using in_case_pattern_list, because we're not parsing
  2647.            anything while we're reading a $( ) construct.  Maybe we
  2648.            should move that whole mess into the yacc parser. */
  2649.         if (character == ')')
  2650.           {
  2651.         if (delimiter && delimited_paren_level)
  2652.           delimited_paren_level--;
  2653.  
  2654.         if (!delimiter && dollar_paren_level)
  2655.           {
  2656.             dollar_paren_level--;
  2657.             goto got_character;
  2658.           }
  2659.           }
  2660.  
  2661.         if (character == ']')
  2662.           {
  2663.         if (!delimiter && dollar_bracket_level)
  2664.           {
  2665.             dollar_bracket_level--;
  2666.             goto got_character;
  2667.           }
  2668.           }
  2669.       }
  2670.  
  2671.     if (!dollar_paren_level && !dollar_bracket_level && !delimiter &&
  2672.         member (character, " \t\n;&()|<>"))
  2673.       {
  2674.         shell_ungetc (character);
  2675.         goto got_token;
  2676.       }
  2677.     
  2678.     if (!delimiter)
  2679.       {
  2680.         if (character == '"' || character == '`' || character == '\'')
  2681.           {
  2682.         quoted = 1;
  2683.         delimiter = character;
  2684.         goto got_character;
  2685.           }
  2686.       }
  2687.  
  2688.     if (all_digits) all_digits = digit (character);
  2689.     if (character == '$') dollar_present = 1;
  2690.  
  2691.       got_character:
  2692.  
  2693.     token[token_index++] = character;
  2694.  
  2695.     if (token_index == (token_buffer_size - 1))
  2696.       token = (char *)xrealloc (token, (token_buffer_size
  2697.                         += TOKEN_DEFAULT_GROW_SIZE));
  2698.     {
  2699.       char *decode_prompt_string ();
  2700.  
  2701.     next_character:
  2702.       if (character == '\n' && interactive && yy_input_type != st_string)
  2703.         prompt_again ();
  2704.     }
  2705.     /* We want to remove quoted newlines (that is, a \<newline> pair)
  2706.        unless we are within single quotes or pass_next_character is
  2707.        set (the shell equivalent of literal-next). */
  2708.     character = shell_getc ((delimiter != '\'') && (!pass_next_character));
  2709.       }
  2710.  
  2711.   got_token:
  2712.  
  2713.     token[token_index] = '\0';
  2714.     
  2715.     if ((delimiter || dollar_paren_level || dollar_bracket_level) && character == EOF)
  2716.       {
  2717.     if (dollar_paren_level && !delimiter)
  2718.       delimiter = ')';
  2719.     else if (dollar_bracket_level && !delimiter)
  2720.       delimiter = ']';
  2721.  
  2722.     report_error ("Unexpected EOF.  Looking for `%c'.", delimiter);
  2723.     return (-1);
  2724.       }
  2725.  
  2726.     if (all_digits)
  2727.       {
  2728.     /* Check to see what thing we should return.  If the last_read_token
  2729.        is a `<', or a `&', or the character which ended this token is
  2730.        a '>' or '<', then, and ONLY then, is this input token a NUMBER.
  2731.        Otherwise, it is just a word, and should be returned as such. */
  2732.  
  2733.     if ((character == '<' || character == '>') ||
  2734.         (last_read_token == LESS_AND ||
  2735.          last_read_token == GREATER_AND))
  2736.       {
  2737.         yylval.number = atoi (token); /* was sscanf (token, "%d", &(yylval.number)); */
  2738.         return (NUMBER);
  2739.       }
  2740.       }
  2741.  
  2742.     /* Handle special case.  IN is recognized if the last token
  2743.        was WORD and the token before that was FOR or CASE. */
  2744.     if ((last_read_token == WORD) &&
  2745.     ((token_before_that == FOR) || (token_before_that == CASE)) &&
  2746.     (STREQ (token, "in")))
  2747.       {
  2748.     if (token_before_that == CASE)
  2749.       {
  2750.         in_case_pattern_list = 1;
  2751.         allow_esac_as_next++;
  2752.       }
  2753.     return (IN);
  2754.       }
  2755.  
  2756.     /* Ditto for DO in the FOR case. */
  2757.     if ((last_read_token == WORD) && (token_before_that == FOR) &&
  2758.     (STREQ (token, "do")))
  2759.       return (DO);
  2760.  
  2761.     /* Ditto for ESAC in the CASE case. 
  2762.        Specifically, this handles "case word in esac", which is a legal
  2763.        construct, certainly because someone will pass an empty arg to the
  2764.        case construct, and we don't want it to barf.  Of course, we should
  2765.        insist that the case construct has at least one pattern in it, but
  2766.        the designers disagree. */
  2767.     if (allow_esac_as_next)
  2768.       {
  2769.     allow_esac_as_next--;
  2770.     if (STREQ (token, "esac"))
  2771.       {
  2772.         in_case_pattern_list = 0;
  2773.         return (ESAC);
  2774.       }
  2775.       }
  2776.  
  2777.     /* Ditto for `{' in the FUNCTION case. */
  2778.     if (allow_open_brace)
  2779.       {
  2780.     allow_open_brace = 0;
  2781.     if (STREQ (token, "{"))
  2782.       {
  2783.         open_brace_awaiting_satisfaction++;
  2784.         return ('{');
  2785.       }
  2786.       }
  2787.  
  2788. #ifdef ALIAS
  2789.     /* OK, we have a token.  Let's try to alias expand it, if (and only if)
  2790.        it's eligible. 
  2791.  
  2792.        Criteria:
  2793.         No dollar sign
  2794.         Unquoted
  2795.         Not all digits
  2796.         An identifier (all alphanumeric or underscore, first character
  2797.         is not a digit)
  2798.         Last token read was a command separator or expand_next_alias
  2799.         is set
  2800.         We are currently processing an alias (pushed_string_list is
  2801.         non-empty) and this token is not the same as the alias we're
  2802.         currently processing (or any alias we have previously
  2803.         processed.
  2804.  
  2805.        Special cases that disqualify:
  2806.         In a pattern list in a case statement (in_case_pattern_list)
  2807.     */
  2808.     if (interactive_shell && !dollar_present && !quoted &&
  2809.     !all_digits && !in_case_pattern_list &&
  2810.     (command_token_position (last_read_token) || expand_next_token))
  2811.       {
  2812.     char *alias_expand_word (), *expanded;
  2813.     if (current_token_being_expanded &&
  2814.          ((STREQ (token, current_token_being_expanded)) ||
  2815.           (token_has_been_expanded (token))))
  2816.       goto no_expansion;
  2817.  
  2818.     expanded = alias_expand_word (token);
  2819.     if (expanded)
  2820.       {
  2821.         int len = strlen (expanded), expand_next;
  2822.         char *temp;
  2823.  
  2824.         token_index = 0;    /* effectively erase current token */
  2825.  
  2826.         expand_next = (expanded[len - 1] == ' ') ||
  2827.               (expanded[len - 1] == '\t');
  2828.  
  2829.         temp = savestring (token);
  2830.         push_string (expanded, expand_next, temp);
  2831.         goto re_read_token;
  2832.       }
  2833.     else
  2834.       /* This is an eligible token that does not have an expansion. */
  2835. no_expansion:
  2836.       expand_next_token = 0;
  2837.       }
  2838.     else
  2839.       {
  2840.     expand_next_token = 0;
  2841.       }
  2842. #endif /* ALIAS */
  2843.  
  2844.     /* Check to see if it is a reserved word.  */
  2845.     if (!dollar_present && !quoted &&
  2846.     reserved_word_acceptable (last_read_token))
  2847.       {
  2848.     int i;
  2849.     for (i = 0; token_word_alist[i].word != (char *)NULL; i++)
  2850.       if (STREQ (token, token_word_alist[i].word))
  2851.         {
  2852.           if (token_word_alist[i].token == '{')
  2853.         open_brace_awaiting_satisfaction++;
  2854.  
  2855.           if (in_case_pattern_list && (token_word_alist[i].token != ESAC))
  2856.         break;
  2857.  
  2858.           if (token_word_alist[i].token == ESAC)
  2859.         in_case_pattern_list = 0;
  2860.  
  2861.           return (token_word_alist[i].token);
  2862.         }
  2863.       }
  2864.  
  2865.     /* What if we are attempting to satisfy an open-brace grouper? */
  2866.     if (open_brace_awaiting_satisfaction && strcmp (token, "}") == 0)
  2867.       {
  2868.     open_brace_awaiting_satisfaction--;
  2869.     return ('}');
  2870.       }
  2871.  
  2872.     the_word = (WORD_DESC *)xmalloc (sizeof (WORD_DESC));
  2873.     the_word->word = (char *)xmalloc (1 + strlen (token));
  2874.     strcpy (the_word->word, token);
  2875.     the_word->dollar_present = dollar_present;
  2876.     the_word->quoted = quoted;
  2877.     the_word->assignment = assignment (token);
  2878.  
  2879.     yylval.word = the_word;
  2880.     result = WORD;
  2881.     if (last_read_token == FUNCTION)
  2882.       allow_open_brace = 1;
  2883.   }
  2884.   return (result);
  2885. }
  2886.  
  2887. #if defined (NOTDEF)        /* Obsoleted function no longer used. */
  2888. /* Return 1 if this token is a legal shell `identifier'; that is, it consists
  2889.    solely of letters, digits, and underscores, and does not begin with a 
  2890.    digit. */
  2891. legal_identifier (name)
  2892.      char *name;
  2893. {
  2894.   register char *s;
  2895.  
  2896.   if (!name || !*name)
  2897.     return (0);
  2898.  
  2899.   if (digit (*name))
  2900.     return (0);
  2901.  
  2902.   for (s = name; s && *s; s++)
  2903.     {
  2904.       if (!isletter (*s) && !digit (*s) && (*s != '_'))
  2905.     return (0);
  2906.     }
  2907.   return (1);
  2908. }
  2909. #endif /* NOTDEF */
  2910.  
  2911. #ifdef ALIAS
  2912. /* Return 1 if TOKEN is a command separating token. */
  2913. command_token_position (token)
  2914.      int token;
  2915. {
  2916.   if (member (token, "\n;(|&{") ||
  2917.       token == AND_AND ||
  2918.       token == OR_OR ||
  2919.       token == BANG ||        /* XXX */
  2920.       token == 0)
  2921.     return (1);
  2922.   else
  2923.     return (0);
  2924. }
  2925. #endif /* ALIAS */
  2926.  
  2927. /* Return 1 if TOKEN is a token that after being read would allow
  2928.    a reserved word to be seen, else 0. */
  2929. reserved_word_acceptable (token)
  2930.      int token;
  2931. {
  2932.   if (member (token, "\n;()|&{") ||
  2933.       token == AND_AND ||
  2934.       token == OR_OR ||
  2935.       token == SEMI_SEMI ||
  2936.       token == DO ||
  2937.       token == IF ||
  2938.       token == WHILE ||
  2939.       token == UNTIL ||
  2940.       token == THEN ||
  2941.       token == ELSE ||
  2942.       token == ELIF ||
  2943.       token == BANG ||
  2944.       token == 0)
  2945.     return (1);
  2946.   else
  2947.     return (0);
  2948. }
  2949.  
  2950. #if defined (READLINE)
  2951. /* Called after each time readline is called.  This insures that whatever
  2952.    the new prompt string is gets propagated to readline's local prompt
  2953.    variable. */
  2954. reset_readline_prompt ()
  2955. {
  2956.   if (prompt_string_pointer && *prompt_string_pointer)
  2957.     {
  2958.       char *temp_prompt, *decode_prompt_string ();
  2959.  
  2960.       temp_prompt = decode_prompt_string (*prompt_string_pointer);
  2961.  
  2962.       if (!temp_prompt)
  2963.     temp_prompt = savestring ("");
  2964.  
  2965.       if (current_readline_prompt)
  2966.     free (current_readline_prompt);
  2967.  
  2968.       current_readline_prompt = temp_prompt;
  2969.     }
  2970. }
  2971. #endif
  2972.  
  2973. /* Issue a prompt, or prepare to issue a prompt when the next character
  2974.    is read. */
  2975. prompt_again ()
  2976. {
  2977.   char *temp_prompt, *decode_prompt_string ();
  2978.  
  2979.   ps1_prompt = get_string_value ("PS1");
  2980.   ps2_prompt = get_string_value ("PS2");
  2981.  
  2982.   if (!prompt_string_pointer)
  2983.     prompt_string_pointer = &ps1_prompt;
  2984.  
  2985.   if (*prompt_string_pointer)
  2986.     temp_prompt = decode_prompt_string (*prompt_string_pointer);
  2987.   else
  2988.     temp_prompt = savestring ("");
  2989.  
  2990.   current_prompt_string = *prompt_string_pointer;
  2991.   prompt_string_pointer = &ps2_prompt;
  2992.  
  2993. #if defined (READLINE)
  2994.   if (!no_line_editing)
  2995.     {
  2996.       if (current_readline_prompt)
  2997.     free (current_readline_prompt);
  2998.       
  2999.       current_readline_prompt = temp_prompt;
  3000.     }
  3001.   else
  3002. #endif    /* READLINE */
  3003.     {
  3004.       if (interactive)
  3005.     {
  3006.       fprintf (stderr, "%s", temp_prompt);
  3007.       fflush (stderr);
  3008.     }
  3009.       free (temp_prompt);
  3010.     }
  3011. }
  3012.  
  3013. /* This sucks. but it is just a crock for System V systems.  The whole idea
  3014.    of MAXPATHLEN is a crock if you ask me.  Why can't we just have
  3015.    dynamically defined sizes?  (UCSB crashes every 20 minutes on me.) */
  3016. #ifndef MAXPATHLEN
  3017. #define MAXPATHLEN 1024
  3018. #endif    /* MAXPATHLEN */
  3019.  
  3020. /* Return a string which will be printed as a prompt.  The string
  3021.    may contain special characters which are decoded as follows:
  3022.    
  3023.     \t    the time
  3024.     \d    the date
  3025.     \n    CRLF
  3026.     \s    the name of the shell
  3027.     \w    the current working directory
  3028.     \W    the last element of PWD
  3029.     \u    your username
  3030.     \h    the hostname
  3031.     \#    the command number of this command
  3032.     \!    the history number of this command
  3033.     \$    a $ or a # if you are root
  3034.     \<octal> character code in octal
  3035.     \\    a backslash
  3036. */
  3037. #include <sys/param.h>
  3038. #include <time.h>
  3039.  
  3040. #define PROMPT_GROWTH 50
  3041. char *
  3042. decode_prompt_string (string)
  3043.      char *string;
  3044. {
  3045.   int result_size = PROMPT_GROWTH;
  3046.   int result_index = 0;
  3047.   char *result = (char *)xmalloc (PROMPT_GROWTH);
  3048.   int c;
  3049.   char *temp = (char *)NULL;
  3050.  
  3051.   result[0] = 0;
  3052.   while (c = *string++)
  3053.     {
  3054.       if (c == '\\')
  3055.     {
  3056.       c = *string;
  3057.  
  3058.       switch (c)
  3059.         {
  3060.  
  3061.         case '0':
  3062.         case '1':
  3063.         case '2':
  3064.         case '3':
  3065.         case '4':
  3066.         case '5':
  3067.         case '6':
  3068.         case '7':
  3069.           {
  3070.         char octal_string[4];
  3071.         int n;
  3072.  
  3073.         strncpy (octal_string, string, 3);
  3074.         octal_string[3] = '\0';
  3075.  
  3076.         n = read_octal (octal_string);
  3077.  
  3078.         temp = savestring ("\\");
  3079.         if (n != -1)
  3080.           {
  3081.             string += 3;
  3082.             temp[0] = n;
  3083.           }
  3084.  
  3085.         c = 0;
  3086.         goto add_string;
  3087.           }
  3088.       
  3089.         case 't':
  3090.         case 'd':
  3091.  
  3092.           /* Make the current time/date into a string. */
  3093.           {
  3094.         long the_time = time (0);
  3095.         char *ttemp = ctime (&the_time);
  3096.         temp = savestring (ttemp);
  3097.  
  3098.         if (c == 't')
  3099.           {
  3100.             strcpy (temp, temp + 11);
  3101.             temp[8] = '\0';
  3102.           }
  3103.         else
  3104.           temp[10] = '\0';
  3105.  
  3106.         goto add_string;
  3107.           }
  3108.  
  3109.         case 'n':
  3110.           temp = savestring ("\r\n");
  3111.           goto add_string;
  3112.  
  3113.         case 's':
  3114.           {
  3115.         extern char *shell_name;
  3116.         temp = savestring (shell_name);
  3117.         goto add_string;
  3118.           }
  3119.     
  3120.         case 'w':
  3121.         case 'W':
  3122.           {
  3123.         /* Use the value of PWD because it is much more effecient. */
  3124. #define EFFICIENT
  3125. #ifdef EFFICIENT
  3126.         char *polite_directory_format (), t_string[MAXPATHLEN];
  3127.  
  3128.         temp = get_string_value ("PWD");
  3129.  
  3130.         if (!temp)
  3131.           getwd (t_string);
  3132.         else
  3133.           strcpy (t_string, temp);
  3134. #else
  3135.         getwd (t_string);
  3136. #endif    /* EFFICIENT */
  3137.  
  3138.         if (c == 'W')
  3139.           {
  3140.             char *dir = (char *)rindex (t_string, '/');
  3141.             if (dir && dir != t_string)
  3142.               strcpy (t_string, dir + 1);
  3143.             temp = savestring (t_string);
  3144.           }
  3145.         else
  3146.           temp = savestring (polite_directory_format (t_string));
  3147.         goto add_string;
  3148.           }
  3149.       
  3150.         case 'u':
  3151.           {
  3152.         extern char *current_user_name;
  3153.         temp = savestring (current_user_name);
  3154.  
  3155.         goto add_string;
  3156.           }
  3157.  
  3158.         case 'h':
  3159.           {
  3160.         extern char *current_host_name;
  3161.         char *t_string;
  3162.  
  3163.         temp = savestring (current_host_name);
  3164.         if (t_string = (char *)index (temp, '.'))
  3165.           *t_string = '\0';
  3166.         
  3167.         goto add_string;
  3168.           }
  3169.  
  3170.         case '#':
  3171.           {
  3172.         extern int current_command_number;
  3173.         char number_buffer[20];
  3174.         sprintf (number_buffer, "%d", current_command_number);
  3175.         temp = savestring (number_buffer);
  3176.         goto add_string;
  3177.           }
  3178.  
  3179.         case '!':
  3180.           {
  3181.         extern int history_base, where_history ();
  3182.         char number_buffer[20];
  3183.  
  3184.         using_history ();
  3185.         if (get_string_value ("HISTSIZE"))
  3186.           sprintf (number_buffer, "%d",
  3187.                history_base + where_history ());
  3188.         else
  3189.           strcpy (number_buffer, "!");
  3190.         temp = savestring (number_buffer);
  3191.         goto add_string;
  3192.           }
  3193.  
  3194.         case '$':
  3195.           temp = savestring (geteuid () == 0 ? "#" : "$");
  3196.           goto add_string;
  3197.  
  3198.         case '\\':
  3199.           temp = savestring ("\\");
  3200.           goto add_string;
  3201.  
  3202.         default:
  3203.           temp = savestring ("\\ ");
  3204.           temp[1] = c;
  3205.  
  3206.         add_string:
  3207.           if (c)
  3208.         string++;
  3209.           result =
  3210.         (char *)sub_append_string (temp, result,
  3211.                        &result_index, &result_size);
  3212.           temp = (char *)NULL; /* Free ()'ed in sub_append_string (). */
  3213.           result[result_index] = '\0';
  3214.           break;
  3215.         }
  3216.     }
  3217.       else
  3218.     {
  3219.       while (3 + result_index > result_size)
  3220.         result = (char *)xrealloc (result, result_size += PROMPT_GROWTH);
  3221.  
  3222.       result[result_index++] = c;
  3223.       result[result_index] = '\0';
  3224.     }
  3225.     }
  3226.  
  3227.   /* I don't really think that this is a good idea.  Do you? */
  3228.   if (!find_variable ("NO_PROMPT_VARS"))
  3229.     {
  3230.       WORD_LIST *expand_string (), *list;
  3231.       char *string_list ();
  3232.  
  3233.       list = expand_string (result, 1);
  3234.       free (result);
  3235.       result = string_list (list);
  3236.       dispose_words (list);
  3237.     }
  3238.  
  3239.   return (result);
  3240. }
  3241.  
  3242. /* Report a syntax error, and restart the parser.  Call here for fatal
  3243.    errors. */
  3244. yyerror ()
  3245. {
  3246.   report_syntax_error ((char *)NULL);
  3247.   reset_parser ();
  3248. }
  3249.  
  3250. /* Report a syntax error with line numbers, etc.
  3251.    Call here for recoverable errors.  If you have a message to print,
  3252.    then place it in MESSAGE, otherwise pass NULL and this will figure
  3253.    out an appropriate message for you. */
  3254. report_syntax_error (message)
  3255.      char *message;
  3256. {
  3257.   if (message)
  3258.     {
  3259.       if (!interactive)
  3260.     {
  3261.       char *name = stream_name ? stream_name : "stdin";
  3262.       report_error ("%s:%d: `%s'", name, line_number, message);
  3263.     }
  3264.       else
  3265.     report_error ("%s", message);
  3266.  
  3267.       return;
  3268.     }
  3269.  
  3270.   if (shell_input_line && *shell_input_line)
  3271.     {
  3272.       char *error_token, *t = shell_input_line;
  3273.       register int i = shell_input_line_index;
  3274.       int token_end = 0;
  3275.  
  3276.       if (!t[i] && i)
  3277.     i--;
  3278.  
  3279.       while (i && (t[i] == ' ' || t[i] == '\t' || t[i] == '\n'))
  3280.     i--;
  3281.  
  3282.       if (i)
  3283.     token_end = i + 1;
  3284.  
  3285.       while (i && !member (t[i], " \n\t;|&"))
  3286.     i--;
  3287.  
  3288.       while (i != token_end && member (t[i], " \n\t"))
  3289.     i++;
  3290.  
  3291.       if (token_end)
  3292.     {
  3293.       error_token = (char *)alloca (1 + (token_end - i));
  3294.       strncpy (error_token, t + i, token_end - i);
  3295.       error_token[token_end - i] = '\0';
  3296.  
  3297.       report_error ("syntax error near `%s'", error_token);
  3298.     }
  3299.       else if ((i == 0) && (token_end == 0))    /* a 1-character token */
  3300.     {
  3301.       error_token = (char *) alloca (2);
  3302.       strncpy(error_token, t + i, 1);
  3303.       error_token[1] = '\0';
  3304.  
  3305.       report_error ("syntax error near `%s'", error_token);
  3306.     }
  3307.  
  3308.       if (!interactive)
  3309.     {
  3310.       char *temp = savestring (shell_input_line);
  3311.       char *name = stream_name ? stream_name : "stdin";
  3312.       int l = strlen (temp);
  3313.  
  3314.       while (l && temp[l - 1] == '\n')
  3315.         temp[--l] = '\0';
  3316.  
  3317.       report_error ("%s:%d: `%s'", name, line_number, temp);
  3318.       free (temp);
  3319.     }
  3320.     }
  3321.   else
  3322.     report_error ("Syntax error");
  3323. }
  3324.  
  3325. /* ??? Needed function. ??? We have to be able to discard the constructs
  3326.    created during parsing.  In the case of error, we want to return
  3327.    allocated objects to the memory pool.  In the case of no error, we want
  3328.    to throw away the information about where the allocated objects live.
  3329.    (dispose_command () will actually free the command. */
  3330. discard_parser_constructs (error_p)
  3331.      int error_p;
  3332. {
  3333. /*   if (error_p) {
  3334.      fprintf (stderr, "*");
  3335.   } */
  3336. }
  3337.    
  3338. /* Do that silly `type "bye" to exit' stuff.  You know, "ignoreeof". */
  3339.  
  3340. /* The number of times that we have encountered an EOF character without
  3341.    another character intervening.  When this gets above the limit, the
  3342.    shell terminates. */
  3343. int eof_encountered = 0;
  3344.  
  3345. /* The limit for eof_encountered. */
  3346. int eof_encountered_limit = 10;
  3347.  
  3348. /* If we have EOF as the only input unit, this user wants to leave
  3349.    the shell.  If the shell is not interactive, then just leave.
  3350.    Otherwise, if ignoreeof is set, and we haven't done this the
  3351.    required number of times in a row, print a message. */
  3352. handle_eof_input_unit ()
  3353. {
  3354.   extern int login_shell, EOF_Reached;
  3355.  
  3356.   if (interactive)
  3357.     {
  3358.       /* If the user wants to "ignore" eof, then let her do so, kind of. */
  3359.       if (find_variable ("ignoreeof") || find_variable ("IGNOREEOF"))
  3360.     {
  3361.       if (eof_encountered < eof_encountered_limit)
  3362.         {
  3363.           fprintf (stderr, "Use \"%s\" to leave the shell.\n",
  3364.                login_shell ? "logout" : "exit");
  3365.           eof_encountered++;
  3366.           /* Reset the prompt string to be $PS1. */
  3367.           prompt_string_pointer = (char **)NULL;
  3368.           prompt_again ();
  3369.           last_read_token = current_token = '\n';
  3370.           return;
  3371.         } 
  3372.     }
  3373.  
  3374.       /* In this case EOF should exit the shell.  Do it now. */
  3375.       reset_parser ();
  3376.       exit_builtin ((WORD_LIST *)NULL);
  3377.     }
  3378.   else
  3379.     {
  3380.       /* We don't write history files, etc., for non-interactive shells. */
  3381.       EOF_Reached = 1;
  3382.     }
  3383. }
  3384.